package com.tulele.vtool.bus.service.impl;

import com.google.common.collect.Lists;
import com.tulele.vtool.bus.mapper.ArticleGzhInfoMapper;
import com.tulele.vtool.bus.mapper.ArticleInfoMapper;
import com.tulele.vtool.bus.mapper.SysRealmMessageMapper;
import com.tulele.vtool.bus.mapper.UserPunchClockInfoMapper;
import com.tulele.vtool.bus.model.*;
import com.tulele.vtool.bus.service.*;
import com.tulele.vtool.model.PlatformSysInfo;
import com.tulele.vtool.util.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

@Component
@Service
@Slf4j
public class ArticleProfessionalServiceImpl implements IArticleProfessionalService {

    @Autowired
    private ArticleInfoMapper articleInfoMapper;

    @Autowired
    private IUserBrandService userBrandService;

    @Autowired
    private IUserService userService;

    @Autowired
    private RedisCacheUtil redisCacheUtil;

    @Autowired
    private IUserPunchClockInfoService userPunchClockInfoService;

    @Autowired
    private UserPunchClockInfoMapper userPunchClockInfoMapper;

    @Autowired
    private ArticleGzhInfoMapper articleGzhInfoMapper;

    @Autowired
    private IMessageDictInfoService messageDictInfoService;

    @Value("${NotInvolvedInActivities}")
    private String notInvolvedInActivities;//不参与活动的 公众号

    @Value("${RecommendedCourses}")
    private String recommendedCourses;//推课程的 公众号

    @Autowired
    private SysRealmMessageMapper sysRealmMessageMapper;

    @Autowired
    private SysGzhService sysGzhService;

    static Map<String,KdxyClass> kdxyClassMap=new HashMap<>();

    //region 原版接口方法

    @Override
    public Integer getUserShareArticleCount(Integer userId) {
        return articleInfoMapper.queryUserShareArticleCount(userId);
    }

    @Override
    public String generateUserShareArticlePushMsg(Integer userId) {

        String pushMsg = "我们为你实时更新文章，包含品牌文章、品牌介绍、产品案例、健康、美妆等\n" +
                "\n" +
                "你还可以编辑文章，插入你的广告哦。\n" +
                "\n" +
                "点击下方【获客素材】，插入你的广告吧。\n" +
                "↓ ↓ ↓ ↓";

        return pushMsg;
    }

    @Override
    public String generateFirstShareArticlePushMsg(Integer userId, Integer articleId,String profile) {
        PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(profile);
        final String frontDomain =sysGzh.getSysGzh().getRealmMessage();

        ArticleInfo articleInfo = articleInfoMapper.queryArticleInfoByArticleId(articleId);

        String pushMsg = String.format(SysConstant.USER_LOOK_ARTICLE_INFO_PUSH_MSG, articleInfo.getArticleTitle());
        pushMsg = pushMsg.replace(SysConstant.frontDomain, frontDomain);//替换域名 20200218
        return pushMsg;
    }

    @Override
    public String generateUserPushArticleInfoV2(Integer userId, int pushTimeType,String profile) {
        PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(profile);
        final String frontDomain =sysGzh.getSysGzh().getRealmMessage();

        log.info("********** ArticleServiceImpl generateUserPushArticleInfoV2" + ",[userId]=" + userId + ",[pushTimeType]=" + pushTimeType);

        List<UserBrandInfo> userBrandInfoList = userBrandService.getUserSubBrandInfo(userId);

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        List<ArticleInfo> brandArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        //如果没有设置关注的品牌，则正能量2篇，情感2篇，健康1篇，励志1篇
        if (CollectionUtils.isEmpty(userBrandInfoList)) {

            typeArticleInfoList = getAllToBePushTypeArticleInfo(userId, 2, 2, 1, 1);
        }

        //如果用户只关注了一个品牌，则该品牌取热度最高的三篇，且一周之内不能重复推送
        if (userBrandInfoList.size() == 1) {

            brandArticleInfoList = getToBePushBrandArticleInfo(userId, userBrandInfoList.get(0).getBrandId());

            typeArticleInfoList = getAllToBePushTypeArticleInfo(userId, 2, 2, 1, 1);

        } else if (userBrandInfoList.size() == 2) {

            //用户关注了两个品牌，则各取热度最高的两篇，且一周之内不能重复推送
            List<ArticleInfo> brandArticleInfoListOne = getToBePushBrandArticleInfo(userId, userBrandInfoList.get(0).getBrandId());

            List<ArticleInfo> brandArticleInfoListTwo = getToBePushBrandArticleInfo(userId, userBrandInfoList.get(1).getBrandId());

            brandArticleInfoList.addAll(brandArticleInfoListOne);
            brandArticleInfoList.addAll(brandArticleInfoListTwo);

            if (!CollectionUtils.isEmpty(brandArticleInfoList) && brandArticleInfoList.size() >= 4) { //品牌文章>=4篇

                typeArticleInfoList = getAllToBePushTypeArticleInfo(userId, 1, 1, 1, 1);


            } else if (!CollectionUtils.isEmpty(brandArticleInfoList) && brandArticleInfoList.size() == 3) {//品牌文章3篇

                typeArticleInfoList = getAllToBePushTypeArticleInfo(userId, 2, 1, 1, 1);


            } else if (!CollectionUtils.isEmpty(brandArticleInfoList) && brandArticleInfoList.size() <= 2) {//品牌文章<=2篇

                typeArticleInfoList = getAllToBePushTypeArticleInfo(userId, 2, 2, 1, 1);

            }

        } else if (userBrandInfoList.size() >= 3) {

            Integer brandId = userBrandInfoList.get(0).getBrandId();
            //如果用户关注的品牌数目大于3，则只处理用户当前选中的品牌
            UserBrandInfo userBrandInfo = userBrandService.getUserSelectedBrandInfo(userId);
            if (userBrandInfo != null && userBrandInfo.getBrandId() != null) {
                brandId = userBrandInfo.getBrandId();
            }

            brandArticleInfoList = getToBePushBrandArticleInfo(userId, brandId);

            typeArticleInfoList = getAllToBePushTypeArticleInfo(userId, 2, 2, 1, 1);


        }

        StringBuffer wxPushMsg = new StringBuffer();
        UserInfo userInfo = userService.queryUserInfo(userId);
        String nickName = "热文更新";
        if (userInfo != null && StringUtils.isNotBlank(userInfo.getNickName())) {
            nickName = userInfo.getNickName();
        }

        wxPushMsg.append(nickName + "\n\n");

        int brandArticleInfoSize = brandArticleInfoList != null ? brandArticleInfoList.size() : 0;
        int typeArticleInfoSize = typeArticleInfoList != null ? typeArticleInfoList.size() : 0;

        int totalArticleInfoSize = brandArticleInfoSize + typeArticleInfoSize;

        if (pushTimeType == 1 || pushTimeType == 4) {

            //获取打卡文章信息
            PunchClockArticleInfo punchClockArticleInfo = getUserClockArticleInfo(userId);
            if (punchClockArticleInfo != null && punchClockArticleInfo.getId() != null) {

                int clockDays = userPunchClockInfoService.getUserClockDays(userId);
                if (clockDays == 0) {
                    clockDays = 1;
                }

                String amPm = "早安";
                if (pushTimeType == 4) {
                    amPm = "晚安";
                }

                if (totalArticleInfoSize < 8) {

                    String punchClockArticleTitle = punchClockArticleInfo.getClockArticleTitle();
                    if (StringUtils.isBlank(punchClockArticleTitle)) {
                        punchClockArticleTitle = "一起坚持打卡，传播正能量";
                    }

                    wxPushMsg.append("\uD83C\uDF37<a href='" + frontDomain + "/index.html'>" + amPm + "打卡 第 " + clockDays + " 天: " + punchClockArticleTitle + "</a>\n\n");

                } else if (totalArticleInfoSize >= 8) {

                    if (!CollectionUtils.isEmpty(typeArticleInfoList) && typeArticleInfoSize > 0) {
                        typeArticleInfoList.remove(0);
                    }

                    String punchClockArticleTitle = punchClockArticleInfo.getClockArticleTitle();
                    if (StringUtils.isBlank(punchClockArticleTitle)) {
                        punchClockArticleTitle = "一起坚持打卡，传播正能量";
                    }

                    wxPushMsg.append("\uD83C\uDF37<a href='" + frontDomain + "/index.html'>" + amPm + "打卡 第 " + clockDays + " 天: " + punchClockArticleTitle + "</a>\n\n");

                }

            }

        }

        if (!CollectionUtils.isEmpty(brandArticleInfoList) && brandArticleInfoList.size() > 0) {

            brandArticleInfoList.forEach(info -> {
                wxPushMsg.append("\ue11d<a href='" + frontDomain + "pages/article/detail.html?t=2&userId=" + userId + "&articleId=" + info.getId() + "'>" + info.getArticleTitle() + "</a>\n\n");
            });

        }

        if (!CollectionUtils.isEmpty(typeArticleInfoList) && typeArticleInfoList.size() > 0) {

            typeArticleInfoList.forEach(info -> {
                wxPushMsg.append("\ue11d<a href='" + frontDomain + "pages/article/detail.html?t=2&userId=" + userId + "&articleId=" + info.getId() + "'>" + info.getArticleTitle() + "</a>\n\n");
            });

        }

        wxPushMsg.append("点击下方<a href=\"" + frontDomain + "/list.html\">【获客素材】</a>，更多爆文\n\n");

        wxPushMsg.append("\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=设置推送频率&msgmenuid=+++\">设置文章推送频率</a>");

        return wxPushMsg.toString();
    }

    @Override
    public String generateUserPushArticleInfoV3(Integer userId, int pushTimeType,String profile) {
        PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(profile);

        final String frontDomain =sysGzh.getSysGzh().getRealmMessage();

        log.info("********** ArticleServiceImpl generateUserPushArticleInfoV3" + ",[userId]=" + userId + ",[pushTimeType]=" + pushTimeType);

        UserInfo userInfo = userService.queryUserInfo(userId);

        if (userInfo == null) {
            return "";
        }

        List<UserBrandInfo> userBrandInfoList = userBrandService.getUserSubBrandInfo(userId);

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        List<ArticleInfo> brandArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        //如果没有设置关注的品牌，则直播2篇，正能量2篇，情感2篇，健康1篇
        //最多8篇，不然超出 微信 内容限制
        if (CollectionUtils.isEmpty(userBrandInfoList)) {

            if (profile.equals(SysConstant.PROFILES_ACTIVE_PRODBST)) {//如果是播商推手
                typeArticleInfoList = getAllToBePushTypeArticleInfo_bst(userId, 2, 2, 2, 1);
            } else if (profile.equals(SysConstant.PROFILES_ACTIVE_PRODYYSCK) || profile.equals(SysConstant.PROFILES_ACTIVE_PRODYYZS)) {  //有鱼助手 和 素材库
                typeArticleInfoList = getAllToBePushTypeArticleInfo_yyzs(userId, 2, 2, 2, 1);
            } else {
                typeArticleInfoList = getAllToBePushTypeArticleInfo(userId, 2, 2, 2, 1);
            }
        }

        //如果用户只关注了一个品牌，则该品牌取热度最高的3篇，且一周之内不能重复推送
        if (userBrandInfoList.size() == 1) {

            brandArticleInfoList = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 3);

            if (profile.equals(SysConstant.PROFILES_ACTIVE_PRODBST)) {//如果是播商推手
                typeArticleInfoList = getAllToBePushTypeArticleInfo_bst(userId, 1, 1, 1, 0);
            } else if (profile.equals(SysConstant.PROFILES_ACTIVE_PRODYYSCK) || profile.equals(SysConstant.PROFILES_ACTIVE_PRODYYZS)) {  //有鱼助手 和 素材库
                typeArticleInfoList = getAllToBePushTypeArticleInfo_yyzs(userId, 1, 1, 1, 0);
            } else {
                typeArticleInfoList = getAllToBePushTypeArticleInfo(userId, 1, 1, 1, 0);
            }
        } else if (userBrandInfoList.size() == 2) {

            //用户关注了两个品牌，则各取热度最高的2篇，且一周之内不能重复推送
            List<ArticleInfo> brandArticleInfoListOne = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 2);

            List<ArticleInfo> brandArticleInfoListTwo = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(1), 2);

            brandArticleInfoList.addAll(brandArticleInfoListOne);
            brandArticleInfoList.addAll(brandArticleInfoListTwo);
            if (profile.equals(SysConstant.PROFILES_ACTIVE_PRODBST)) {//如果是播商推手
                typeArticleInfoList = getAllToBePushTypeArticleInfo_bst(userId, 1, 1, 0, 0);
            } else if (profile.equals(SysConstant.PROFILES_ACTIVE_PRODYYSCK) || profile.equals(SysConstant.PROFILES_ACTIVE_PRODYYZS)) {  //有鱼助手 和 素材库
                typeArticleInfoList = getAllToBePushTypeArticleInfo_yyzs(userId, 1, 1, 0, 0);
            } else {
                typeArticleInfoList = getAllToBePushTypeArticleInfo(userId, 1, 1, 0, 0);
            }
        } else if (userBrandInfoList.size() == 3) {

            //用户关注了3个品牌
            List<ArticleInfo> brandArticleInfoListOne = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 2);

            List<ArticleInfo> brandArticleInfoListTwo = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(1), 1);

            List<ArticleInfo> brandArticleInfoListThree = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(2), 1);

            brandArticleInfoList.addAll(brandArticleInfoListOne);
            brandArticleInfoList.addAll(brandArticleInfoListTwo);
            brandArticleInfoList.addAll(brandArticleInfoListThree);
            if (profile.equals(SysConstant.PROFILES_ACTIVE_PRODBST)) {//如果是播商推手
                typeArticleInfoList = getAllToBePushTypeArticleInfo_bst(userId, 1, 1, 0, 0);
            } else if (profile.equals(SysConstant.PROFILES_ACTIVE_PRODYYSCK) || profile.equals(SysConstant.PROFILES_ACTIVE_PRODYYZS)) {  //有鱼助手 和 素材库
                typeArticleInfoList = getAllToBePushTypeArticleInfo_yyzs(userId, 1, 1, 0, 0);
            } else {
                typeArticleInfoList = getAllToBePushTypeArticleInfo(userId, 1, 1, 0, 0);
            }
        } else if (userBrandInfoList.size() >= 4) {

            //用户关注了4个以上品牌
            List<ArticleInfo> brandArticleInfoListOne = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 1);

            List<ArticleInfo> brandArticleInfoListTwo = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(1), 1);

            List<ArticleInfo> brandArticleInfoListThree = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(2), 1);

            List<ArticleInfo> brandArticleInfoListFour = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(3), 1);

            brandArticleInfoList.addAll(brandArticleInfoListOne);
            brandArticleInfoList.addAll(brandArticleInfoListTwo);
            brandArticleInfoList.addAll(brandArticleInfoListThree);
            brandArticleInfoList.addAll(brandArticleInfoListFour);
            if (profile.equals(SysConstant.PROFILES_ACTIVE_PRODBST)) {//如果是播商推手
                typeArticleInfoList = getAllToBePushTypeArticleInfo_bst(userId, 1, 1, 0, 0);
            } else if (profile.equals(SysConstant.PROFILES_ACTIVE_PRODYYSCK) || profile.equals(SysConstant.PROFILES_ACTIVE_PRODYYZS)) {  //有鱼助手 和 素材库
                typeArticleInfoList = getAllToBePushTypeArticleInfo_yyzs(userId, 1, 1, 0, 0);
            } else {
                typeArticleInfoList = getAllToBePushTypeArticleInfo(userId, 1, 1, 0, 0);
            }
        }

        //String articleAccessDomain = SysConstant.ARTICLE_ACCESS_DETAIL_DOMAIN_PROD;

        //String profile = SpringContextUtil.getActiveProfile();
//        if (SysConstant.PROFILES_ACTIVE_DEV.equals(profile)) {
//
//            articleAccessDomain = SysConstant.ARTICLE_ACCESS_DETAIL_DOMAIN_DEV;
//
//        }

        final String finalArticleAccessDomain = frontDomain;

        StringBuffer wxPushMsg = new StringBuffer();

        String nickName = "热文更新";
        if (userInfo != null && StringUtils.isNotBlank(userInfo.getNickName())) {
            nickName = userInfo.getNickName();
        }

        wxPushMsg.append(nickName + "\n\n");

        int brandArticleInfoSize = brandArticleInfoList != null ? brandArticleInfoList.size() : 0;
        int typeArticleInfoSize = typeArticleInfoList != null ? typeArticleInfoList.size() : 0;

        int totalArticleInfoSize = brandArticleInfoSize + typeArticleInfoSize;

        if (pushTimeType == 2 || pushTimeType == 3 || pushTimeType == 4) {
            if (userInfo.getVipStatus() == null || userInfo.getVipStatus().equals(0)) { //非会员
                String strVip = "";

                if (pushTimeType == 2 || pushTimeType == 3) {
                    strVip = "\uD83D\uDD13<a href='" +sysGzh.getOpenMemberMenuUrl() + "?mt=1'>开通会员，激活客户追踪功能</a>\n\n";
                }
                wxPushMsg.append(strVip);
            }
        }


        //20200210 hyl 用户当天 没打卡才 发送(已作废)
        String clockTimeStr = DateUtil.getFormatDate("yyyy-MM-dd", DateUtil.getCurDate());
        int clockStatus = Optional.ofNullable(userPunchClockInfoMapper.queryUserSpecialDayPunchClockStatus(userId, clockTimeStr)).orElse(0);
        //20200224 hyl 用户当天 打不打都发送，因为一天 只推两次
        //if (clockStatus == 0) {
        if (pushTimeType == 1 || pushTimeType == 4) {

            //获取打卡文章信息
            PunchClockArticleInfo punchClockArticleInfo = getUserClockArticleInfo(userId);
            if (punchClockArticleInfo != null && punchClockArticleInfo.getId() != null) {

                int clockDays = userPunchClockInfoService.getUserClockDays(userId);
//                    if (clockDays == 0) {
//                        clockDays = 1;
//                    }
                if (clockStatus == 0) { //20200229 hyl，用户当天没打 才加1
                    clockDays = clockDays + 1;
                }

                String amPm = "早安";
                if (pushTimeType == 4) {
                    amPm = "晚安";
                }
                String punchClockArticleTitle = punchClockArticleInfo.getClockArticleTitle();
                if (StringUtils.isBlank(punchClockArticleTitle)) {
                    punchClockArticleTitle = "一起坚持打卡，传播正能量";
                }
                wxPushMsg.append("\uD83C\uDF37<a href=\"weixin://bizmsgmenu?msgmenucontent=" + amPm + "&msgmenuid=+++\">" + amPm + "打卡 第 " + clockDays + " 天: " + punchClockArticleTitle + "</a>\n\n");
            }
        }
        //}

        if (!CollectionUtils.isEmpty(brandArticleInfoList) && brandArticleInfoList.size() > 0) {

            brandArticleInfoList.forEach(info -> {

                //20200516 控制标题长度 hyl
                String articleTitle = info.getArticleTitle().length() > 30 ? info.getArticleTitle().substring(0, 29) + "…" : info.getArticleTitle();

                if (info.getResourceType() != null && info.getResourceType().equals(2)) {//2视频
                    wxPushMsg.append("\uD83C\uDFA6<a href='" + finalArticleAccessDomain + "pages/video/index.html?t=2&userId=" + userId + "&articleId=" + info.getId() + "'>" + articleTitle + "</a>\n\n");
                } else {
                    wxPushMsg.append("\ue11d<a href='" + finalArticleAccessDomain + "pages/article/detail.html?t=2&userId=" + userId + "&articleId=" + info.getId() + "'>" + articleTitle + "</a>\n\n");
                }
            });

        }

        if (!CollectionUtils.isEmpty(typeArticleInfoList) && typeArticleInfoList.size() > 0) {

            typeArticleInfoList.forEach(info -> {
                //20200516 控制标题长度 hyl
                String articleTitle = info.getArticleTitle().length() > 30 ? info.getArticleTitle().substring(0, 29) + "…" : info.getArticleTitle();

                if (info.getResourceType() != null && info.getResourceType().equals(2)) {//2视频
                    wxPushMsg.append("\uD83D\uDCCE<a href='" + finalArticleAccessDomain + "pages/video/index.html?t=2&userId=" + userId + "&articleId=" + info.getId() + "'>" + articleTitle + "</a>\n\n");
                } else {
                    wxPushMsg.append("\uD83D\uDCCE<a href='" + finalArticleAccessDomain + "pages/article/detail.html?t=2&userId=" + userId + "&articleId=" + info.getId() + "'>" + articleTitle + "</a>\n\n");
                }
            });

        }

        //wxPushMsg.append("点击下方<a href=\""+ finalArticleAccessDomain +"/list.html\">【获客爆文】</a>，更多爆文\n\n");
        wxPushMsg.append("\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=获取爆文&msgmenuid=+++\">换一批爆文</a>\n\n");

        if (pushTimeType == 1 || pushTimeType == 2) {
            wxPushMsg.append("\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=更多爆文&msgmenuid=+++\">更多爆文</a>\t" +
                    "\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=更多视频&msgmenuid=+++\">更多视频</a>\n\n");

            wxPushMsg.append("\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=客服&msgmenuid=+++\">专属客服一对一开单指导</a>");

        }

        if (pushTimeType == 5) {

            wxPushMsg.append("\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=更多爆文&msgmenuid=+++\">更多爆文</a>\t" +
                    "\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=更多视频&msgmenuid=+++\">更多视频</a>\n\n");

            wxPushMsg.append("\uD83D\uDCB0<a href=\"weixin://bizmsgmenu?msgmenucontent=邀请有奖&msgmenuid=+++\">赚点奖励金</a>\n\n");
        }

        if (pushTimeType == 3) {

            wxPushMsg.append("\uD83D\uDCB0<a href=\"weixin://bizmsgmenu?msgmenucontent=邀请有奖&msgmenuid=+++\">赚点奖励金</a>\t" +
                    "\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=客服&msgmenuid=+++\">联系客服</a>\n\n");

            wxPushMsg.append("<a href='" + finalArticleAccessDomain + "/pages/setting/remind.html'>点击这里设置文章推送频率</a>");
        }

        if (pushTimeType == 4) {

            wxPushMsg.append("\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=更多爆文&msgmenuid=+++\">更多爆文</a>\t" +
                    "\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=更多视频&msgmenuid=+++\">更多视频</a>\n\n");

            wxPushMsg.append("\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=客户&msgmenuid=+++\">点击这里盘点今天邀请情况</a>");
        }

        //wxPushMsg.append("<a href='"+ finalArticleAccessDomain +"/pages/setting/remind.html'>点击这里设置文章推送频率</a>");

        return wxPushMsg.toString();
    }

    @Override
    public String generateUserPushArticleInfoSixthTime(String nickName, Integer vipStatus,String profile) {
        PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(profile);

        StringBuffer wxPushMsg = new StringBuffer();
        wxPushMsg.append("\uD83C\uDF4E" + nickName + "，忙了一整天，坐下来盘点一下今天的收获吧\n\n");
        /*wxPushMsg.append("\uD83D\uDE80<a href=\"weixin://bizmsgmenu?msgmenucontent=人脉广场&msgmenuid=+++\">增加点人脉</a>\n\n");*/
        wxPushMsg.append("\uD83D\uDCB0<a href=\"weixin://bizmsgmenu?msgmenucontent=奖励金&msgmenuid=+++\">查看我的奖金</a>\n\n");
        wxPushMsg.append("\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=获取爆文&msgmenuid=+++\">看看最新爆文</a>\n\n");
        wxPushMsg.append("\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=意向客户&msgmenuid=+++\">盘点今日准客户</a>\n\n");


        //非会员才推
        if (vipStatus == null || !vipStatus.equals(1)) {
            wxPushMsg.append("\uD83D\uDD13<a href=\"" +sysGzh.getOpenMemberMenuUrl() + "?mt=1\">看不到访客名单？点我解锁</a>");
            //wxPushMsg.append("\uD83C\uDF81\uD83C\uDF81\uD83C\uDF81热辣七月<a href=\"" + openMemberMenuUrl + "\">❗❗会员大促来袭❗❗>></a>");
        }
        //wxPushMsg.append("\t\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=客服&msgmenuid=+++\">咨询客服导师</a>\n\n");
        //wxPushMsg.append("\t\uD83C\uDF8A<a href=\"weixin://bizmsgmenu?msgmenucontent=活动详情&msgmenuid=+++\">会员限时特惠活动</a>");
        //wxPushMsg.append("祝明天更好\t\uD83C\uDF39\t\uD83C\uDF39\t\uD83C\uDF39");
        return wxPushMsg.toString();
    }

    @Override
    public String generateUserPushArticleInfoFirstTime(Integer userId,String profile) throws Exception {
        PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(profile);
        final String frontDomain = sysGzh.getSysGzh().getRealmMessage();
        UserInfo userInfo = userService.queryUserInfo(userId);

        if (userInfo == null) {
            return "";
        }

        StringBuffer wxPushMsg = new StringBuffer();
        wxPushMsg.append("⛅" + userInfo.getNickName() + "，早上好\uD83C\uDF3F\n\n");
        LocalDate now = LocalDate.now();

        Integer week = now.getDayOfWeek().getValue();
        String weekStr = "";
        switch (week) {
            case 1:
                weekStr = "星期一";
                break; //可选
            case 2:
                weekStr = "星期二";
                break; //可选
            case 3:
                weekStr = "星期三";
                break; //可选
            case 4:
                weekStr = "星期四";
                break; //可选
            case 5:
                weekStr = "星期五";
                break; //可选
            case 6:
                weekStr = "星期六";
                break; //可选
            case 7:
                weekStr = "星期天";
                break; //可选
            default: //可选
                weekStr = "";
        }

        wxPushMsg.append("今天是" + now.getYear() + "年" + now.getMonthValue() + "月" + now.getDayOfMonth() + "日 " + weekStr + "\n\n");
        //wxPushMsg.append("最新的早安心语&热门文章已经为您准备好！\n\n");//平时

        Integer number = new Random().nextInt(10) + 1;
        wxPushMsg.append("\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=早安&msgmenuid=+++\">点击一起参与》早安打卡</a>\n\n");

        List<UserBrandInfo> userBrandInfoList = userBrandService.getUserSubBrandInfo(userId);
        List<ArticleInfo> brandArticleInfoList = Lists.newArrayListWithExpectedSize(10);
        brandArticleInfoList = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 1);

        UserBrandInfo ub = new UserBrandInfo();
        String tit="";
        if (profile != null && profile.equals("prodzx1")) {//装小编
            ub.setBrandId(24441);
            tit="装修";
        } else if (profile != null && profile.equals("prodhyxt")) { //护眼学堂
            ub.setBrandId(15509);//护眼知识
            tit="护眼";
        } else if (profile != null && profile.equals("prodshjj")) { //私护之家
            ub.setBrandId(14182);//私护
            tit="私护";
        } else if (profile != null && profile.equals("prodbkwz")) { //鼻康微站
            ub.setBrandId(17115);//鼻腔康复
            tit="鼻康";
        }else if (profile != null && profile.equals("back_zkt")) { //测试
            ub.setBrandId(17115);//测试
            tit="装修";
        }

        List<ArticleInfo> brandVideoInfoList = getToBePushBrandVideoInfo(userId, ub, 1);
        brandArticleInfoList.addAll(brandArticleInfoList.size(), brandVideoInfoList);

        wxPushMsg.append("====="+tit+"早课堂=====\n\n");

        if(SysConstant.CLICK_BACK_GZH_ARR.contains(profile)) {
            wxPushMsg.append(getArticleInfoUrlClick(brandArticleInfoList, null, profile, userId));
        }else{
            wxPushMsg.append(getArticleInfoUrl(brandArticleInfoList, null, profile, userId, frontDomain));
        }

        wxPushMsg.append("\uD83D\uDD25<a href=\"weixin://bizmsgmenu?msgmenucontent=获取爆文&msgmenuid=+++\">换一批</a>\t" +
                "\uD83D\uDD25<a href=\"weixin://bizmsgmenu?msgmenucontent=更多视频&msgmenuid=+++\">更多视频</a>");

        String isActivity = sysRealmMessageMapper.getConfigValueByKey(SysConstant.IsActivity);
        if (userInfo.getVipStatus() == null || userInfo.getVipStatus().equals(0)) { //非会员

            String vipMsgKey = SysConstant.VIP_6;
            if (isActivity.equals("1") && !notInvolvedInActivities.contains("|" + profile + "|")) { //活动状态下，而且 不包含在 “不参与活动的公众号名单”中
                vipMsgKey = SysConstant.VIP_P_6_A;
            }

            String strVip = messageDictInfoService.getLinkMsgByKey(vipMsgKey, frontDomain, profile) ;

            wxPushMsg.append("\n\n");
            wxPushMsg.append(strVip);
        }
        //平时 end

        String funMsgKey=SysConstant.FUN_P_6_A;
        if(isActivity.equals("1") && !notInvolvedInActivities.contains("|" + profile + "|")) { //活动状态下，而且 不包含在 “不参与活动的公众号名单”中
            funMsgKey=SysConstant.FUN_P_6_A;
        }
        wxPushMsg.append("\n\n"+messageDictInfoService.getLinkMsgByKey(funMsgKey, frontDomain,profile));
        //wxPushMsg.append("\n\n<a href=\"weixin://bizmsgmenu?msgmenucontent=人脉广场&msgmenuid=+++\">人脉不够，我们这里有~点击这里加粉丝 >></a>");

        return wxPushMsg.toString();
    }

    @Override
    public String positiveEnergyMsgString(Integer userId,String profile) {
        PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(profile);

        StringBuffer wxPushMsg = new StringBuffer();

        UserInfo userInfo = userService.queryUserInfo(userId);

        if (userInfo == null) {
            return "";
        }

        String nickName = "热文更新";
        if (userInfo != null && StringUtils.isNotBlank(userInfo.getNickName())) {
            nickName = userInfo.getNickName();
        }

        String clockTimeStr = DateUtil.getFormatDate("yyyy-MM-dd", DateUtil.getCurDate());
        int clockStatus = Optional.ofNullable(userPunchClockInfoMapper.queryUserSpecialDayPunchClockStatus(userId, clockTimeStr)).orElse(0);

        final String frontDomain =sysGzh.getSysGzh().getRealmMessage();

        //获取打卡文章信息
        PunchClockArticleInfo punchClockArticleInfo = getUserClockArticleInfo(userId);
        if (punchClockArticleInfo != null && punchClockArticleInfo.getId() != null) {


            int clockDays = userPunchClockInfoService.getUserClockDays(userId);

            if (clockStatus == 0) { //20200229 hyl，用户当天没打 才加1
                clockDays = clockDays + 1;
            }

            //String amPm = userInfo.getNickName()+"，早上好！点击领取您的早安心语";
            wxPushMsg.append(nickName + "，美好的一天从分享开始~\n\n");//平时
            //wxPushMsg.append("\uD83C\uDF81元旦祝福来啦，点击蓝字领取\n\n");//元旦
            String punchClockArticleTitle = punchClockArticleInfo.getClockArticleTitle();
//                if (StringUtils.isBlank(punchClockArticleTitle)) {
//                    punchClockArticleTitle = "一起坚持打卡，传播正能量";
//                }
            wxPushMsg.append("\uD83C\uDF39<a href=\"" + frontDomain + "/index.html\">早安打卡 第 " + clockDays + " 天: " + punchClockArticleTitle + "</a>\n\n");
        }

        List<ArticleInfo> articleInfos = this.articleInfoMapper.selectArticleInfoByArticleTypePositiveEnergy();

        //20210201 获取待推送文章(正能量)
        List<ArticleInfo> standArticleStand= articleInfoMapper.queryArticleStandList(1,null);
        articleInfos.addAll(0,standArticleStand);

        if (!CollectionUtils.isEmpty(articleInfos) && articleInfos.size() > 0) {

            //articleInfos.forEach(info -> {
            int size=articleInfos.size();
            if(size>8)size=8;
            for(int i=0;i<size;i++) {
                //20200516 控制标题长度 hyl
                ArticleInfo info=articleInfos.get(i);
                String articleTitle = info.getArticleTitle().length() > 30 ? info.getArticleTitle().substring(0, 29) + "…" : info.getArticleTitle();

                if (info.getResourceType() != null && info.getResourceType().equals(2)) {//2视频
                    wxPushMsg.append("\uD83C\uDFAC <a href='" + frontDomain + "pages/video/index.html?t=2&userId=" + userId + "&articleId=" + info.getId() + "'>" + articleTitle + "</a>\n\n");
                } else {
                    wxPushMsg.append("➜ <a href='" + frontDomain + "pages/article/detail.html?t=2&userId=" + userId + "&articleId=" + info.getId() + "'>" + articleTitle + "</a>\n\n");
                }
            }
            //});

            //平时
//            wxPushMsg.append("\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=更多爆文&msgmenuid=+++\">更多爆文</a>\t"+
//                    "\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=更多视频&msgmenuid=+++\">更多视频</a>\n\n");
//
//            wxPushMsg.append("\uD83D\uDCB0<a href=\"weixin://bizmsgmenu?msgmenucontent=邀请有奖&msgmenuid=+++\">赚点奖励金</a>\n\n");
            //平时

            wxPushMsg.append("--------------------\n\n");
            wxPushMsg.append("\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=获取正能量文章&msgmenuid=+++\">换一批</a>");


        }
        return wxPushMsg.toString();
    }

    //endregion

    //region 文章类子方法

    /**
     * 从缓存中获取最后推送的文章ID
     *
     * @param userId
     * @return
     */
    private int getLastPushArticleId(Integer userId, Integer articleBrandId) {

        int lastPushArticleId = 0;

        Object lastPushArticleIdObj = redisCacheUtil.getCacheObject(userId + "lastPushArticleId" + articleBrandId);
        if (lastPushArticleIdObj != null) {
            lastPushArticleId = (Integer) lastPushArticleIdObj;
        }

        return lastPushArticleId;

    }

    private List<ArticleInfo> getRecommendHotArticleInfoByTypeForRand(Integer articleTypeId, Integer recordSize) {

        Object typeArticleInfoListObj = redisCacheUtil.getCacheObject("recordSize" + recordSize + "recommendHotArticleInfoByType" + articleTypeId);

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayList();
        if (typeArticleInfoListObj == null) {

            typeArticleInfoList = articleInfoMapper.queryRecommendHotArticleInfoByType(articleTypeId, recordSize);

            if (!CollectionUtils.isEmpty(typeArticleInfoList) && typeArticleInfoList.size() > 0) {

                redisCacheUtil.setCacheObject("recordSize" + recordSize + "recommendHotArticleInfoByType" + articleTypeId, typeArticleInfoList, 7200);

            }

        } else {

            typeArticleInfoList = (List<ArticleInfo>) typeArticleInfoListObj;

        }

        return typeArticleInfoList;

    }

    private List<ArticleInfo> getRecommendHotArticleInfoByBrandForRand(Integer articleBrandId) {

        Object brandArticleInfoListObj = redisCacheUtil.getCacheObject("recommendHotArticleInfoByBrand" + articleBrandId);

        List<ArticleInfo> brandArticleInfoList = Lists.newArrayList();
        if (brandArticleInfoListObj == null) {

            brandArticleInfoList = articleInfoMapper.queryRecommendHotArticleInfoByBrand(articleBrandId);

            if (!CollectionUtils.isEmpty(brandArticleInfoList) && brandArticleInfoList.size() > 0) {

                redisCacheUtil.setCacheObject("recommendHotArticleInfoByBrand" + articleBrandId, brandArticleInfoList, 7200);

            }

        } else {

            brandArticleInfoList = (List<ArticleInfo>) brandArticleInfoListObj;

        }

        return brandArticleInfoList;

    }

    /**
     * 根据创建时间获取品牌推荐文章信息
     *
     * @param articleBrandId
     * @return
     */
    private List<ArticleInfo> getRecommendArticleInfoByBrandForHotValue(Integer articleBrandId, Integer recordSize) {

        Object brandArticleInfoListObj = redisCacheUtil.getCacheObject("recommendHotArticleInfo2ByBrandForHotValue" + articleBrandId);

        List<ArticleInfo> brandArticleInfoList = Lists.newArrayList();
        if (brandArticleInfoListObj == null) {

            brandArticleInfoList = articleInfoMapper.queryArticleInfoByArticleBrandForHotScore(articleBrandId, recordSize);

            if (!CollectionUtils.isEmpty(brandArticleInfoList) && brandArticleInfoList.size() > 0) {

                redisCacheUtil.setCacheObject("recommendHotArticleInfo2ByBrandForHotValue" + articleBrandId, brandArticleInfoList, 7200);

            }

        } else {

            brandArticleInfoList = (List<ArticleInfo>) brandArticleInfoListObj;

        }

        return brandArticleInfoList;

    }

    /**
     * 根据创建时间获取品牌推荐文章信息
     *
     * @param articleBrandId
     * @return
     */
    public List<ArticleInfo> getArticleInfoByBrandForCreateTime(Integer articleBrandId, Integer recordSize) {

        return getRecommendArticleInfoByBrandForHotValue(articleBrandId, recordSize);

    }

    /**
     * 根据创建时间获取行业推荐文章信息
     *
     * @param articleTypeId
     * @return
     */
    public List<ArticleInfo> getArticleInfoByTypeForCreateTime(Integer articleTypeId, Integer recordSize){
        return getRecommendArticleInfoByTypeForHotValue(articleTypeId, recordSize);
    }


    /**
     * 获取已经推送给用户的品牌文章ID
     *
     * @param userId
     * @param brandId
     * @return
     */
    private List<Integer> getUserAlreadyPushBrandArticleIds(Integer userId, Integer brandId) {

        List<Integer> userAlreadyPushArticleIds = Lists.newArrayList();

        Object userAlreadyPushArticleIdsObj = redisCacheUtil.getCacheObject(userId + "userAlreadyPushBrandArticleIds" + brandId);
        if (userAlreadyPushArticleIdsObj != null) {
            userAlreadyPushArticleIds = (List<Integer>) userAlreadyPushArticleIdsObj;
        }

        //满一周就清空
        if (!CollectionUtils.isEmpty(userAlreadyPushArticleIds) && userAlreadyPushArticleIds.size() >= 54) {
            redisCacheUtil.removeSingleCache(userId + "userAlreadyPushBrandArticleIds" + brandId);
            userAlreadyPushArticleIds = Lists.newArrayList();
        }

        return userAlreadyPushArticleIds;
    }

    /**
     * 获取已经推送给用户的品牌文章ID
     *
     * @param userId
     * @param brandId
     * @return
     */
    private List<Integer> getUserAlreadyPushBrandArticleIds2(Integer userId, Integer brandId, Integer articleCount) {

        List<Integer> userAlreadyPushArticleIds = Lists.newArrayList();

        Object userAlreadyPushArticleIdsObj = redisCacheUtil.getCacheObject(userId + "userAlreadyPushBrandArticleIds" + brandId);
        if (userAlreadyPushArticleIdsObj != null) {
            userAlreadyPushArticleIds = (List<Integer>) userAlreadyPushArticleIdsObj;
        }

        if (articleCount >= 105) {//一天15篇，一周105篇
            articleCount = 105;
        }

        //满一周就清空
        if (!CollectionUtils.isEmpty(userAlreadyPushArticleIds) && (userAlreadyPushArticleIds.size() >= articleCount)) {
            redisCacheUtil.removeSingleCache(userId + "userAlreadyPushBrandArticleIds" + brandId);
            userAlreadyPushArticleIds = Lists.newArrayList();
        }

        return userAlreadyPushArticleIds;
    }

    /**
     * 获取已经推送给用户的类型文章ID
     *
     * @param userId
     * @param typeId
     * @return
     */
    private List<Integer> getUserAlreadyPushTypeArticleIds(Integer userId, Integer typeId) {

        List<Integer> userAlreadyPushArticleIds = Lists.newArrayList();

        Object userAlreadyPushArticleIdsObj = redisCacheUtil.getCacheObject(userId + "userAlreadyPushTypeArticleIds" + typeId);
        if (userAlreadyPushArticleIdsObj != null) {
            userAlreadyPushArticleIds = (List<Integer>) userAlreadyPushArticleIdsObj;
        }

        if (!CollectionUtils.isEmpty(userAlreadyPushArticleIds) && userAlreadyPushArticleIds.size() >= 54) {
            redisCacheUtil.removeSingleCache(userId + "userAlreadyPushTypeArticleIds" + typeId);
            userAlreadyPushArticleIds = Lists.newArrayList();
        }

        return userAlreadyPushArticleIds;
    }

    /**
     * 获取已经推送给用户的品牌文章ID
     *
     * @param userId
     * @param articleIds
     * @return
     */
    private void setUserAlreadyPushBrandArticleIds(Integer userId, Integer brandId, List<Integer> articleIds) {

        //缓存7天时间
        redisCacheUtil.setCacheObject(userId + "userAlreadyPushBrandArticleIds" + brandId, articleIds, 604800);

    }

    /**
     * 获取已经推送给用户的类型文章ID
     *
     * @param userId
     * @param articleIds
     * @return
     */
    private void setUserAlreadyPushTypeArticleIds(Integer userId, Integer typeId, List<Integer> articleIds) {

        //缓存7天时间
        redisCacheUtil.setCacheObject(userId + "userAlreadyPushTypeArticleIds" + typeId, articleIds, 604800);

    }

    /**
     * 获取待推送的品牌文章信息
     *
     * @param userId
     * @param brandId
     * @return
     */
    private List<ArticleInfo> getToBePushBrandArticleInfo(Integer userId, Integer brandId) {

        List<ArticleInfo> brandArticleInfoList = Lists.newArrayListWithExpectedSize(3);

        Integer articleBrandId = brandId;
        List<ArticleInfo> platformArticleInfos = getRecommendArticleInfoByBrandForHotValue(articleBrandId, 56);

        //查询用户已经推送的文章信息
        List<Integer> userAlreadyPushArticleIds = getUserAlreadyPushBrandArticleIds(userId, articleBrandId);

        //剔除已经推送过的文章
        List<ArticleInfo> validArticleInfoList = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(userAlreadyPushArticleIds) && userAlreadyPushArticleIds.size() > 0) {

            validArticleInfoList = platformArticleInfos.stream()
                    .filter(articleInfo -> !userAlreadyPushArticleIds.contains(articleInfo.getId()))
                    .collect(Collectors.toList());

        } else {
            validArticleInfoList = platformArticleInfos;
        }

        if (!CollectionUtils.isEmpty(validArticleInfoList) && validArticleInfoList.size() >= 2) {

            ArticleInfo articleInfoOne = validArticleInfoList.get(0);
            ArticleInfo articleInfoTwo = validArticleInfoList.get(1);

            brandArticleInfoList.add(articleInfoOne);
            brandArticleInfoList.add(articleInfoTwo);

            userAlreadyPushArticleIds.add(articleInfoOne.getId());
            userAlreadyPushArticleIds.add(articleInfoTwo.getId());

            //缓存已经发送了的品牌文章ID
            setUserAlreadyPushBrandArticleIds(userId, articleBrandId, userAlreadyPushArticleIds);

        }

        return brandArticleInfoList;

    }

    //region 获取文章分类

    /**
     * 获取待推送的类型文章信息(默认公众号)
     *
     * @param userId
     * @param recordSizeOne
     * @param recordSizeTwo
     * @param recordSizeThree
     * @param recordSizeFour
     * @return
     */
    private List<ArticleInfo> getAllToBePushTypeArticleInfo(Integer userId, int recordSizeOne, int recordSizeTwo, int recordSizeThree, int recordSizeFour) {

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(6);

        List<ArticleInfo> typeArticleInfoOne = getToBePushTypeArticleInfo(userId, 1, recordSizeOne); //正能量
        List<ArticleInfo> typeArticleInfoTwo = getToBePushTypeArticleInfo(userId, 4, recordSizeTwo); //健康
        List<ArticleInfo> typeArticleInfoThree = getToBePushTypeArticleInfo(userId, 3, recordSizeThree); //直销理念
        List<ArticleInfo> typeArticleInfoFour = getToBePushTypeArticleInfo(userId, 2, recordSizeFour); //微商理念

        typeArticleInfoList.addAll(typeArticleInfoOne);
        typeArticleInfoList.addAll(typeArticleInfoTwo);
        typeArticleInfoList.addAll(typeArticleInfoThree);
        typeArticleInfoList.addAll(typeArticleInfoFour);

        return typeArticleInfoList;

    }

    /**
     * 获取待推送的类型文章信息(播商推手，先推“直播”文章)
     *
     * @param userId
     * @param recordSizeOne
     * @param recordSizeTwo
     * @param recordSizeThree
     * @param recordSizeFour
     * @return
     */
    private List<ArticleInfo> getAllToBePushTypeArticleInfo_bst(Integer userId, int recordSizeOne, int recordSizeTwo, int recordSizeThree, int recordSizeFour) {

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(6);

        List<ArticleInfo> typeArticleInfoOne = getToBePushTypeArticleInfo(userId, 1, recordSizeOne); //正能量
        List<ArticleInfo> typeArticleInfoTwo = getToBePushTypeArticleInfo(userId, 4, recordSizeTwo); //健康
        List<ArticleInfo> typeArticleInfoThree = getToBePushTypeArticleInfo(userId, 3, recordSizeThree); //直销理念
        List<ArticleInfo> typeArticleInfoFour = getToBePushTypeArticleInfo(userId, 2, recordSizeFour); //微商理念

        typeArticleInfoList.addAll(typeArticleInfoOne);
        typeArticleInfoList.addAll(typeArticleInfoTwo);
        typeArticleInfoList.addAll(typeArticleInfoThree);
        typeArticleInfoList.addAll(typeArticleInfoFour);

        return typeArticleInfoList;

    }

    /**
     * 获取待推送的类型文章信息(有鱼，先推“吴召国频道”、“思埠公益”文章)
     *
     * @param userId
     * @param recordSizeOne
     * @param recordSizeTwo
     * @param recordSizeThree
     * @param recordSizeFour
     * @return
     */
    private List<ArticleInfo> getAllToBePushTypeArticleInfo_yyzs(Integer userId, int recordSizeOne, int recordSizeTwo, int recordSizeThree, int recordSizeFour) {

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(6);

        List<ArticleInfo> typeArticleInfoOne = getToBePushTypeArticleInfo(userId, 1, recordSizeOne); //正能量
        List<ArticleInfo> typeArticleInfoTwo = getToBePushTypeArticleInfo(userId, 4, recordSizeTwo); //健康
        List<ArticleInfo> typeArticleInfoThree = getToBePushTypeArticleInfo(userId, 3, recordSizeThree); //直销理念
        List<ArticleInfo> typeArticleInfoFour = getToBePushTypeArticleInfo(userId, 2, recordSizeFour); //微商理念
//        List<ArticleInfo> typeArticleInfoOne =  getToBePushTypeArticleInfo(userId, 29, recordSizeOne); //思埠公益
//        List<ArticleInfo> typeArticleInfoTwo =  getToBePushTypeArticleInfo(userId, 0, recordSizeTwo); //直播
//        List<ArticleInfo> typeArticleInfoThree = getToBePushTypeArticleInfo(userId, 1, recordSizeThree); //正能量
//        List<ArticleInfo> typeArticleInfoFour = getToBePushTypeArticleInfo(userId, 20, recordSizeFour); //社交电商

        typeArticleInfoList.addAll(typeArticleInfoOne);
        typeArticleInfoList.addAll(typeArticleInfoTwo);
        typeArticleInfoList.addAll(typeArticleInfoThree);
        typeArticleInfoList.addAll(typeArticleInfoFour);

        return typeArticleInfoList;

    }


    /**
     * 获取待推送的类型文章信息(开单学堂)
     *
     * @param userId
     * @param recordSizeOne
     * @param recordSizeTwo
     * @param recordSizeThree
     * @param recordSizeFour
     * @return
     */
    private List<ArticleInfo> getAllToBePushTypeArticleInfo_PushKDXT(Integer userId, int recordSizeOne, int recordSizeTwo, int recordSizeThree, int recordSizeFour, String gzhCode) {

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(6);

        List<ArticleInfo> typeArticleInfoOne = getToBePushTypeArticleInfo(userId, 1, recordSizeOne); //正能量
        List<ArticleInfo> typeArticleInfoTwo = getToBePushTypeArticleInfo_OverGzh(userId, 49, recordSizeTwo, gzhCode); //开单学堂
        List<ArticleInfo> typeArticleInfoThree = getToBePushTypeArticleInfo(userId, 4, recordSizeThree); //健康
        List<ArticleInfo> typeArticleInfoFour = getToBePushTypeArticleInfo(userId, 3, recordSizeFour); //社交电商

        typeArticleInfoList.addAll(typeArticleInfoOne);
        typeArticleInfoList.addAll(typeArticleInfoTwo);
        typeArticleInfoList.addAll(typeArticleInfoThree);
        typeArticleInfoList.addAll(typeArticleInfoFour);

        return typeArticleInfoList;

    }

    //endregion

    /**
     * 获取待推送的品牌文章信息(可设置数量)
     *
     * @param userId
     * @param userBrandInfo
     * @param count         要获取的文章数
     * @return
     */
    private List<ArticleInfo> getToBePushBrandArticleInfo2(Integer userId, UserBrandInfo userBrandInfo, Integer count) {

        List<ArticleInfo> brandArticleInfoList = Lists.newArrayListWithExpectedSize(count);

        Integer articleBrandId = userBrandInfo.getBrandId();
        List<ArticleInfo> platformArticleInfos = getRecommendArticleInfoByBrandForHotValue(articleBrandId, 200);

        //查询用户已经推送的文章信息
        List<Integer> userAlreadyPushArticleIds = getUserAlreadyPushBrandArticleIds2(userId, articleBrandId, platformArticleInfos.size());

        //剔除已经推送过的文章
        List<ArticleInfo> validArticleInfoList = null;
        if (!CollectionUtils.isEmpty(userAlreadyPushArticleIds) && userAlreadyPushArticleIds.size() > 0
                && ((platformArticleInfos.size() - userAlreadyPushArticleIds.size()) > 0)  //剔除后 还有剩余 才执行剔除
        ) {

            validArticleInfoList = platformArticleInfos.stream()
                    .filter(articleInfo -> !userAlreadyPushArticleIds.contains(articleInfo.getId()))
                    .collect(Collectors.toList());

        } else {
            validArticleInfoList = platformArticleInfos;
        }

        if (validArticleInfoList != null && validArticleInfoList.size() > 0) {

            Integer pushCount = count;
            if (validArticleInfoList.size() < count) {
                pushCount = validArticleInfoList.size();
            }
            for (int i = 0; i < pushCount; i++) {
                ArticleInfo articleInfo = validArticleInfoList.get(i);
                //articleInfo.setArticleTitle("[" + userBrandInfo.getBrandName() + "]" + articleInfo.getArticleTitle());
                brandArticleInfoList.add(articleInfo);
                userAlreadyPushArticleIds.add(articleInfo.getId());
            }

            //缓存已经发送了的品牌文章ID
            setUserAlreadyPushBrandArticleIds(userId, articleBrandId, userAlreadyPushArticleIds);

        }

        return brandArticleInfoList;

    }

    /**
     * 获取用户早晚安打卡文章信息
     *
     * @param userId
     * @return
     */
    private PunchClockArticleInfo getUserClockArticleInfo(Integer userId) {

        PunchClockArticleInfo punchClockArticleInfo = userPunchClockInfoService.getUserPunchClockArticleInfo();

        return punchClockArticleInfo;
    }

    /**
     * 根据热度值获取类型推荐文章信息
     *
     * @param articleTypeId
     * @return
     */
    private List<ArticleInfo> getRecommendArticleInfoByTypeForHotValue(Integer articleTypeId, Integer recordSize) {

        Object typeArticleInfoListObj = redisCacheUtil.getCacheObject("recommendHotArticleInfo2ByTypeForHotValue" + articleTypeId);

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayList();
        if (typeArticleInfoListObj == null) {

            typeArticleInfoList = articleInfoMapper.queryArticleInfoByArticleTypeForHotScore(articleTypeId, recordSize);

            if (!CollectionUtils.isEmpty(typeArticleInfoList) && typeArticleInfoList.size() > 0) {

                redisCacheUtil.setCacheObject("recommendHotArticleInfo2ByTypeForHotValue" + articleTypeId, typeArticleInfoList, 7200);

            }

        } else {

            typeArticleInfoList = (List<ArticleInfo>) typeArticleInfoListObj;

        }

        return typeArticleInfoList;

    }

    /**
     * 获取待推送的类型文章信息
     *
     * @param userId
     * @param articleTypeId
     * @param recordSize
     * @return
     */
    private List<ArticleInfo> getToBePushTypeArticleInfo(Integer userId, Integer articleTypeId, int recordSize) {

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(3);

        if (recordSize > 0) {
            //获取56篇（每天8篇，7天一共56篇）按热度排序的类型文章
            List<ArticleInfo> platformArticleInfos = getRecommendArticleInfoByTypeForHotValue(articleTypeId, 56);

            //20210201 获取待推送文章(正能量)
            List<ArticleInfo> standArticleStand= articleInfoMapper.queryArticleStandList(1,1);
            platformArticleInfos.addAll(0,standArticleStand);

            //查询用户已经推送的文章信息
            List<Integer> userAlreadyPushArticleIds = getUserAlreadyPushTypeArticleIds(userId, articleTypeId);

            //剔除已经推送过的文章
            List<ArticleInfo> validArticleInfoList = Lists.newArrayList();
            if (!CollectionUtils.isEmpty(userAlreadyPushArticleIds) && userAlreadyPushArticleIds.size() > 0) {

                validArticleInfoList = platformArticleInfos.stream()
                        .filter(articleInfo -> !userAlreadyPushArticleIds.contains(articleInfo.getId()))
                        .collect(Collectors.toList());

            } else {
                validArticleInfoList = platformArticleInfos;
            }

            if (!CollectionUtils.isEmpty(validArticleInfoList) && validArticleInfoList.size() > 0) {

                if (recordSize > 0) {

                    for (int i = 0; i < recordSize; i++) {
                        ArticleInfo articleInfo = validArticleInfoList.get(i);
                        typeArticleInfoList.add(articleInfo);

                        userAlreadyPushArticleIds.add(articleInfo.getId());
                    }

                }

                //缓存已经发送了的文章ID
                setUserAlreadyPushTypeArticleIds(userId, articleTypeId, userAlreadyPushArticleIds);

            }
        }
        return typeArticleInfoList;

    }

    /**
     * 获取待推送的类型文章信息(排除公众号专属文章)
     *
     * @param userId
     * @param articleTypeId
     * @param recordSize
     * @return
     */
    @Override
    public List<ArticleInfo> getToBePushTypeArticleInfo_OverGzh(Integer userId, Integer articleTypeId, int recordSize, String gzhCode) {

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(3);

        if (recordSize > 0) {
            List<ArticleInfo> platformArticleInfos = getRecommendArticleInfoByTypeForHotValue(articleTypeId, 1000);

            //查询用户已经推送的文章信息
            List<Integer> userAlreadyPushArticleIds = getUserAlreadyPushTypeArticleIds(userId, articleTypeId);

            //剔除已经推送过的文章
            List<ArticleInfo> validArticleInfoList = Lists.newArrayList();
            if (!CollectionUtils.isEmpty(userAlreadyPushArticleIds) && userAlreadyPushArticleIds.size() > 0) {

                validArticleInfoList = platformArticleInfos.stream()
                        .filter(articleInfo -> !userAlreadyPushArticleIds.contains(articleInfo.getId()))
                        .collect(Collectors.toList());

            } else {
                validArticleInfoList = platformArticleInfos;
            }

            //剔除非当前公众号的文章
            List<Integer> articleGzhInfos = articleGzhInfoMapper.queryList(gzhCode);
            if (!CollectionUtils.isEmpty(articleGzhInfos) && articleGzhInfos.size() > 0) {
                List<ArticleInfo> overGzhArticles = validArticleInfoList.stream()
                        .filter(articleInfo -> !articleGzhInfos.contains(articleInfo.getId()))
                        .collect(Collectors.toList());

                validArticleInfoList = overGzhArticles;
            }

            if (!CollectionUtils.isEmpty(validArticleInfoList) && validArticleInfoList.size() > 0) {

                if (recordSize > 0) {

                    for (int i = 0; i < recordSize; i++) {
                        ArticleInfo articleInfo = validArticleInfoList.get(i);
                        typeArticleInfoList.add(articleInfo);
                        userAlreadyPushArticleIds.add(articleInfo.getId());
                    }
                }

                //缓存已经发送了的文章ID
                setUserAlreadyPushTypeArticleIds(userId, articleTypeId, userAlreadyPushArticleIds);
            }
        }
        return typeArticleInfoList;

    }

    //endregion

    //region 视频类子方法

    final String USER_ALREADY_PUSHTYPE_VIDEOIDS = "userAlreadyPushTypeVideoIds";//已经推送给用户的类型视频ID

    final String USER_ALREADY_PUSHBRAND_VIDEOIDS = "userAlreadyPushBrandVideoIds";//已经推送给用户的品牌视频ID

    final String RECOMMEND_HOTVIDEOINFO_BYTYPE_FORHOTVALUE = "recommendHotVideoInfoByTypeForHotValue";//根据热度值获取类型推荐视频信息

    final String RECOMMEND_HOTVIDEOINFO_BYBRAND_FORHOTVALUE = "recommendHotVideoInfoByBrandForHotValue";//根据热度值获取品牌推荐视频信息

    /**
     * 获取待推送的类型视频信息(默认公众号)
     *
     * @param userId
     * @param recordSizeOne
     * @param recordSizeTwo
     * @param recordSizeThree
     * @param recordSizeFour
     * @return
     */
    private List<ArticleInfo> getAllToBePushTypeVideoInfo(Integer userId, int recordSizeOne, int recordSizeTwo, int recordSizeThree, int recordSizeFour) {

        List<ArticleInfo> typeVideoInfoList = Lists.newArrayListWithExpectedSize(6);

        List<ArticleInfo> typeArticleInfoOne = getToBePushTypeVideoInfo(userId, 1, recordSizeOne); //正能量
        List<ArticleInfo> typeArticleInfoTwo = getToBePushTypeVideoInfo(userId, 0, recordSizeTwo);
        List<ArticleInfo> typeArticleInfoThree = getToBePushTypeVideoInfo(userId, 20, recordSizeThree);
        List<ArticleInfo> typeArticleInfoFour = getToBePushTypeVideoInfo(userId, 4, recordSizeFour);//健康

        typeVideoInfoList.addAll(typeArticleInfoOne);
        typeVideoInfoList.addAll(typeArticleInfoTwo);
        typeVideoInfoList.addAll(typeArticleInfoThree);
        typeVideoInfoList.addAll(typeArticleInfoFour);

        return typeVideoInfoList;

    }

    /**
     * 获取待推送的类型视频信息(开单学堂)
     *
     * @param userId
     * @param recordSizeOne
     * @param recordSizeTwo
     * @param recordSizeThree
     * @param recordSizeFour
     * @return
     */
    private List<ArticleInfo> getAllToBePushTypeVideoInfo_KDXT(Integer userId, int recordSizeOne, int recordSizeTwo, int recordSizeThree, int recordSizeFour) {

        List<ArticleInfo> typeVideoInfoList = Lists.newArrayListWithExpectedSize(6);

        List<ArticleInfo> typeArticleInfoOne = getToBePushTypeVideoInfo(userId, 1, recordSizeOne); //正能量
        List<ArticleInfo> typeArticleInfoTwo = getToBePushTypeVideoInfo(userId, 49, recordSizeTwo); //开单学堂
        List<ArticleInfo> typeArticleInfoThree = getToBePushTypeVideoInfo(userId, 4, recordSizeThree); //健康
        List<ArticleInfo> typeArticleInfoFour = getToBePushTypeVideoInfo(userId, 3, recordSizeFour); //社交电商

        typeVideoInfoList.addAll(typeArticleInfoOne);
        typeVideoInfoList.addAll(typeArticleInfoTwo);
        typeVideoInfoList.addAll(typeArticleInfoThree);
        typeVideoInfoList.addAll(typeArticleInfoFour);

        return typeVideoInfoList;

    }

    /**
     * 获取待推送的类型视频信息(播商推手，先推“直播”文章)
     * @param userId
     * @param recordSizeOne
     * @param recordSizeTwo
     * @param recordSizeThree
     * @param recordSizeFour
     * @return
     */
    /*
    private List<ArticleInfo> getAllToBePushTypeVideoInfo_bst(Integer userId, int recordSizeOne, int recordSizeTwo, int recordSizeThree, int recordSizeFour) {

        List<ArticleInfo> typeVideoInfoList = Lists.newArrayListWithExpectedSize(6);

        List<ArticleInfo> typeArticleInfoOne =  getToBePushTypeVideoInfo(userId, 0, recordSizeOne); //直播
        List<ArticleInfo> typeArticleInfoTwo =  getToBePushTypeVideoInfo(userId, 1, recordSizeTwo); //正能量
        List<ArticleInfo> typeArticleInfoThree = getToBePushTypeVideoInfo(userId, 3, recordSizeThree); //直销理念
        List<ArticleInfo> typeArticleInfoFour = getToBePushTypeVideoInfo(userId, 4, recordSizeFour); //健康

        typeVideoInfoList.addAll(typeArticleInfoOne);
        typeVideoInfoList.addAll(typeArticleInfoTwo);
        typeVideoInfoList.addAll(typeArticleInfoThree);
        typeVideoInfoList.addAll(typeArticleInfoFour);

        return typeVideoInfoList;

    }
    */
    /**
     * 获取待推送的类型视频信息(有鱼，先推“吴召国频道”、“思埠公益”文章)
     * @param userId
     * @param recordSizeOne
     * @param recordSizeTwo
     * @param recordSizeThree
     * @param recordSizeFour
     * @return
     */
    /*
    private List<ArticleInfo> getAllToBePushTypeVideoInfo_yyzs(Integer userId, int recordSizeOne, int recordSizeTwo, int recordSizeThree, int recordSizeFour) {

        List<ArticleInfo> typeVideoInfoList = Lists.newArrayListWithExpectedSize(6);

        List<ArticleInfo> typeArticleInfoOne =  getToBePushTypeVideoInfo(userId, 29, recordSizeOne); //思埠公益
        List<ArticleInfo> typeArticleInfoTwo =  getToBePushTypeVideoInfo(userId, 0, recordSizeTwo); //直播
        List<ArticleInfo> typeArticleInfoThree = getToBePushTypeVideoInfo(userId, 1, recordSizeThree); //正能量
        List<ArticleInfo> typeArticleInfoFour = getToBePushTypeVideoInfo(userId, 20, recordSizeFour); //社交电商

        typeVideoInfoList.addAll(typeArticleInfoOne);
        typeVideoInfoList.addAll(typeArticleInfoTwo);
        typeVideoInfoList.addAll(typeArticleInfoThree);
        typeVideoInfoList.addAll(typeArticleInfoFour);

        return typeVideoInfoList;

    }
*/

    /**
     * 获取待推送的类型视频信息
     *
     * @param userId
     * @param articleTypeId
     * @param recordSize
     * @return
     */
    private List<ArticleInfo> getToBePushTypeVideoInfo(Integer userId, Integer articleTypeId, int recordSize) {

        List<ArticleInfo> typeVideoInfoList = Lists.newArrayListWithExpectedSize(3);

        if (recordSize > 0) {
            //获取56篇（每天8篇，7天一共56篇）按热度排序的类型视频
            List<ArticleInfo> platformArticleInfos = getRecommendVideoInfoByTypeForHotValue(articleTypeId, 56);

            //20210201 获取待推送视频(正能量)
            List<ArticleInfo> standArticleStand= articleInfoMapper.queryArticleStandList(1,2);
            platformArticleInfos.addAll(0,standArticleStand);

            //查询用户已经推送的视频信息
            List<Integer> userAlreadyPushArticleIds = getUserAlreadyPushTypeVideoIds(userId, articleTypeId);

            //剔除已经推送过的视频
            List<ArticleInfo> validVideoInfoList = Lists.newArrayList();
            if (!CollectionUtils.isEmpty(userAlreadyPushArticleIds) && userAlreadyPushArticleIds.size() > 0) {

                validVideoInfoList = platformArticleInfos.stream()
                        .filter(articleInfo -> !userAlreadyPushArticleIds.contains(articleInfo.getId()))
                        .collect(Collectors.toList());

            } else {
                validVideoInfoList = platformArticleInfos;
            }

            if (!CollectionUtils.isEmpty(validVideoInfoList) && validVideoInfoList.size() > 0) {

                if (recordSize > 0) {

                    for (int i = 0; i < recordSize; i++) {
                        ArticleInfo articleInfo = validVideoInfoList.get(i);
                        typeVideoInfoList.add(articleInfo);

                        userAlreadyPushArticleIds.add(articleInfo.getId());
                    }

                }

                //缓存已经发送了的文章ID
                setUserAlreadyPushTypeVideoIds(userId, articleTypeId, userAlreadyPushArticleIds);

            }
        }
        return typeVideoInfoList;

    }

    /**
     * 根据热度值获取类型推荐视频信息
     *
     * @param articleTypeId
     * @return
     */
    private List<ArticleInfo> getRecommendVideoInfoByTypeForHotValue(Integer articleTypeId, Integer recordSize) {

        Object typeVideoInfoListObj = redisCacheUtil.getCacheObject(RECOMMEND_HOTVIDEOINFO_BYTYPE_FORHOTVALUE + articleTypeId);

        List<ArticleInfo> typeVideoInfoList = Lists.newArrayList();
        if (typeVideoInfoListObj == null) {

            typeVideoInfoList = articleInfoMapper.queryVideoInfoByArticleTypeForHotScore(articleTypeId, recordSize);

            if (!CollectionUtils.isEmpty(typeVideoInfoList) && typeVideoInfoList.size() > 0) {

                redisCacheUtil.setCacheObject(RECOMMEND_HOTVIDEOINFO_BYTYPE_FORHOTVALUE + articleTypeId, typeVideoInfoList, 7200);

            }

        } else {

            typeVideoInfoList = (List<ArticleInfo>) typeVideoInfoListObj;

        }

        return typeVideoInfoList;

    }

    /**
     * 获取已经推送给用户的类型视频ID
     *
     * @param userId
     * @param typeId
     * @return
     */
    private List<Integer> getUserAlreadyPushTypeVideoIds(Integer userId, Integer typeId) {

        List<Integer> userAlreadyPushVideos = Lists.newArrayList();

        Object userAlreadyPushArticleIdsObj = redisCacheUtil.getCacheObject(userId + USER_ALREADY_PUSHTYPE_VIDEOIDS + typeId);
        if (userAlreadyPushArticleIdsObj != null) {
            userAlreadyPushVideos = (List<Integer>) userAlreadyPushArticleIdsObj;
        }

        if (!CollectionUtils.isEmpty(userAlreadyPushVideos) && userAlreadyPushVideos.size() >= 10) {
            redisCacheUtil.removeSingleCache(userId + USER_ALREADY_PUSHTYPE_VIDEOIDS + typeId);
            userAlreadyPushVideos = Lists.newArrayList();
        }

        return userAlreadyPushVideos;
    }

    /**
     * 获取已经推送给用户的类型视频ID
     *
     * @param userId
     * @param articleIds
     * @return
     */
    private void setUserAlreadyPushTypeVideoIds(Integer userId, Integer typeId, List<Integer> articleIds) {

        //缓存7天时间
        redisCacheUtil.setCacheObject(userId + USER_ALREADY_PUSHTYPE_VIDEOIDS + typeId, articleIds, 604800);

    }


    /**
     * 获取待推送的品牌文章信息(可设置数量)
     *
     * @param userId
     * @param userBrandInfo
     * @param count         要获取的文章数
     * @return
     */
    private List<ArticleInfo> getToBePushBrandVideoInfo(Integer userId, UserBrandInfo userBrandInfo, Integer count) {

        List<ArticleInfo> brandVideoInfoList = Lists.newArrayListWithExpectedSize(count);

        Integer videoBrandId = userBrandInfo.getBrandId();
        List<ArticleInfo> platformVideoInfos = getRecommendVideoInfoByBrandForHotValue(videoBrandId, 200);

        //查询用户已经推送的文章信息
        List<Integer> userAlreadyPushVideoIds = getUserAlreadyPushBrandVideoIds(userId, videoBrandId, platformVideoInfos.size());

        //剔除已经推送过的文章
        List<ArticleInfo> validArticleInfoList = null;
        if (!CollectionUtils.isEmpty(userAlreadyPushVideoIds) && userAlreadyPushVideoIds.size() > 0
                && ((platformVideoInfos.size() - userAlreadyPushVideoIds.size()) > 0)  //剔除后 还有剩余 才执行剔除
        ) {

            validArticleInfoList = platformVideoInfos.stream()
                    .filter(articleInfo -> !userAlreadyPushVideoIds.contains(articleInfo.getId()))
                    .collect(Collectors.toList());

        } else {
            validArticleInfoList = platformVideoInfos;
        }

        if (validArticleInfoList != null && validArticleInfoList.size() > 0) {

            Integer pushCount = count;
            if (validArticleInfoList.size() < count) {
                pushCount = validArticleInfoList.size();
            }
            for (int i = 0; i < pushCount; i++) {
                ArticleInfo articleInfo = validArticleInfoList.get(i);
                //articleInfo.setArticleTitle("[" + userBrandInfo.getBrandName() + "]" + articleInfo.getArticleTitle());
                brandVideoInfoList.add(articleInfo);
                userAlreadyPushVideoIds.add(articleInfo.getId());
            }

            //缓存已经发送了的品牌文章ID
            setUserAlreadyPushBrandVideoIds(userId, videoBrandId, userAlreadyPushVideoIds);

        }

        return brandVideoInfoList;

    }


    /**
     * 根据热度值获取品牌推荐文章信息
     *
     * @param articleBrandId
     * @return
     */
    private List<ArticleInfo> getRecommendVideoInfoByBrandForHotValue(Integer articleBrandId, Integer recordSize) {

        Object brandVideoInfoListObj = redisCacheUtil.getCacheObject(RECOMMEND_HOTVIDEOINFO_BYBRAND_FORHOTVALUE + articleBrandId);

        List<ArticleInfo> brandVideoInfoList = Lists.newArrayList();
        if (brandVideoInfoListObj == null) {

            brandVideoInfoList = articleInfoMapper.queryVideoInfoByArticleBrandForHotScore(articleBrandId, recordSize);

            if (!CollectionUtils.isEmpty(brandVideoInfoList) && brandVideoInfoList.size() > 0) {

                redisCacheUtil.setCacheObject(RECOMMEND_HOTVIDEOINFO_BYBRAND_FORHOTVALUE + articleBrandId, brandVideoInfoList, 7200);

            }

        } else {

            brandVideoInfoList = (List<ArticleInfo>) brandVideoInfoListObj;

        }

        return brandVideoInfoList;

    }

    /**
     * 获取已经推送给用户的品牌文章ID
     *
     * @param userId
     * @param brandId
     * @return
     */
    private List<Integer> getUserAlreadyPushBrandVideoIds(Integer userId, Integer brandId, Integer articleCount) {

        List<Integer> userAlreadyPushVideoIds = Lists.newArrayList();

        Object userAlreadyPushArticleIdsObj = redisCacheUtil.getCacheObject(userId + USER_ALREADY_PUSHBRAND_VIDEOIDS + brandId);
        if (userAlreadyPushArticleIdsObj != null) {
            userAlreadyPushVideoIds = (List<Integer>) userAlreadyPushArticleIdsObj;
        }

        if (articleCount >= 105) {//一天15篇，一周105篇
            articleCount = 105;
        }

        //满一周就清空
        if (!CollectionUtils.isEmpty(userAlreadyPushVideoIds) && (userAlreadyPushVideoIds.size() >= articleCount)) {
            redisCacheUtil.removeSingleCache(userId + USER_ALREADY_PUSHBRAND_VIDEOIDS + brandId);
            userAlreadyPushVideoIds = Lists.newArrayList();
        }

        return userAlreadyPushVideoIds;
    }

    /**
     * 获取已经推送给用户的品牌视频ID
     *
     * @param userId
     * @param articleIds
     * @return
     */
    private void setUserAlreadyPushBrandVideoIds(Integer userId, Integer brandId, List<Integer> articleIds) {

        //缓存7天时间
        redisCacheUtil.setCacheObject(userId + USER_ALREADY_PUSHBRAND_VIDEOIDS + brandId, articleIds, 604800);

    }

    //endregion

    //region 20200526版推送策略 6:20

    @Override
    public String generateUserPushArticleInfoFirst(Integer userId,String profile) throws Exception {
        PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(profile);
        //log.info("********** ArticleServiceImpl generateUserPushArticleInfoV3"+",[userId]="+userId+",[pushTimeType]="+pushTimeType);

        UserInfo userInfo = userService.queryUserInfo(userId);

        if (userInfo == null) {
            return "";
        }

        List<UserBrandInfo> userBrandInfoList = userBrandService.getUserSubBrandInfo(userId);

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        List<ArticleInfo> brandArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        //如果没有设置关注的品牌，则直播2篇，正能量2篇，情感2篇，健康1篇
        //最多8篇，不然超出 微信 内容限制
        if (CollectionUtils.isEmpty(userBrandInfoList)) {

            typeArticleInfoList = getAllToBePushTypeArticleInfo_PushKDXT(userId, 3, 0, 2, 1, profile);
        }

        //如果用户只关注了一个品牌，则该品牌取热度最高的3篇，且一周之内不能重复推送
        if (userBrandInfoList.size() == 1) {

            brandArticleInfoList = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 2);
            List<ArticleInfo> brandVideoInfoList = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(0), 1);
            brandArticleInfoList.addAll(brandArticleInfoList.size(), brandVideoInfoList);

            List<ArticleInfo> typeVideoInfoList = getAllToBePushTypeVideoInfo(userId, 1, 0, 0, 0);
            typeArticleInfoList.addAll(0, typeVideoInfoList);

            typeArticleInfoList.addAll(typeVideoInfoList.size(), getAllToBePushTypeArticleInfo_PushKDXT(userId, 1, 0, 1, 0, SpringContextUtil.getActiveProfile()));


        } else if (userBrandInfoList.size() >= 2) {

            //用户关注了两个品牌，则各取热度最高的2篇，且一周之内不能重复推送
            List<ArticleInfo> brandArticleInfoListOne = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 1);
            List<ArticleInfo> brandArticleInfoListTwo = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(1), 1);
            List<ArticleInfo> brandVideoInfoList = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(0), 1);


            brandArticleInfoList.addAll(brandArticleInfoListOne);
            brandArticleInfoList.addAll(brandArticleInfoListTwo);
            brandArticleInfoList.addAll(brandArticleInfoList.size(), brandVideoInfoList);

            List<ArticleInfo> typeVideoInfoList = getAllToBePushTypeVideoInfo(userId, 1, 0, 0, 0);
            typeArticleInfoList.addAll(0, typeVideoInfoList);

            typeArticleInfoList.addAll(typeVideoInfoList.size(), getAllToBePushTypeArticleInfo_PushKDXT(userId, 1, 0, 1, 0, SpringContextUtil.getActiveProfile()));

        }

        final String frontDomain =sysGzh.getSysGzh().getRealmMessage();

        StringBuffer wxPushMsg = new StringBuffer();

        String nickName = "热文更新";
        if (userInfo != null && StringUtils.isNotBlank(userInfo.getNickName())) {
            nickName = userInfo.getNickName();
        }

        if(SysConstant.CLICK_BACK_GZH_ARR.contains(profile)) {
            wxPushMsg.append("✅ 领取文章 \uD83C\uDF00 点击蓝色文章标题，拉到底部领取⬇⬇\n\n");
        }else {
            wxPushMsg.append("\uD83D\uDC4D领取成功！精准获客从坚持分享开始~\n\n");
        }

        //20200210 hyl 用户当天 没打卡才 发送(已作废)
        String clockTimeStr = DateUtil.getFormatDate("yyyy-MM-dd", DateUtil.getCurDate());
        int clockStatus = Optional.ofNullable(userPunchClockInfoMapper.queryUserSpecialDayPunchClockStatus(userId, clockTimeStr)).orElse(0);
        //20200224 hyl 用户当天 打不打都发送，因为一天 只推两次


        //获取打卡文章信息
        PunchClockArticleInfo punchClockArticleInfo = getUserClockArticleInfo(userId);
        if (punchClockArticleInfo != null && punchClockArticleInfo.getId() != null) {

            int clockDays = userPunchClockInfoService.getUserClockDays(userId);

            if (clockStatus == 0) { //20200229 hyl，用户当天没打 才加1
                clockDays = clockDays + 1;
            }

            String punchClockArticleTitle = punchClockArticleInfo.getClockArticleTitle();

            Calendar rightNow = Calendar.getInstance();
            int hour = rightNow.get(Calendar.HOUR_OF_DAY);

            String anTxt = "早安";
            if (hour > 16) {
                anTxt = "晚安";
            }

            wxPushMsg.append("\uD83C\uDF39<a href=\"" + frontDomain + "index.html\">" + anTxt + "打卡 第 " + clockDays + " 天: " + punchClockArticleTitle + "</a>\n\n");
        }
        //}

        if(profile.equals("prodshsck")
                || profile.equals("prodhyxt")
                || profile.equals("prodshjj")
                || profile.equals("back_zkt")) {
            wxPushMsg.append("<a data-miniprogram-appid=\"wxfd8301588fd5d875\" data-miniprogram-path=\"/pages/index/index\" href=\"\">全新打卡神器惊艳上线\uD83D\uDE0D快来体验>></a>\n\n");
        }

        String isActivity= sysRealmMessageMapper.getConfigValueByKey(SysConstant.IsActivity);
        if (userInfo.getVipStatus() == null || userInfo.getVipStatus().equals(0)) { //非会员

            String vipMsgKey=SysConstant.VIP_6;
            if(isActivity.equals("1") && !notInvolvedInActivities.contains("|" + profile + "|")) { //活动状态下，而且 不包含在 “不参与活动的公众号名单”中
                if(recommendedCourses.contains("|" + profile + "|")){//活动状态下，而且 包含在 “推送课程的公众号名单”中
                    vipMsgKey = SysConstant.VIP_6_A2;
                }else {
                    vipMsgKey = SysConstant.VIP_6_A;
                }
            }

            String strVip = messageDictInfoService.getLinkMsgByKey(vipMsgKey, frontDomain,profile) + "\n\n";
            wxPushMsg.append(strVip);

        }

        //封装生成文章的方法 start  hyl 20210113
        if(SysConstant.CLICK_BACK_GZH_ARR.contains(profile)) {
            wxPushMsg.append(getArticleInfoUrlClick(brandArticleInfoList, typeArticleInfoList, profile, userId));
        }else {
            wxPushMsg.append(getArticleInfoUrl(brandArticleInfoList, typeArticleInfoList, profile, userId, frontDomain));
        }
        //封装生成文章的方法 end

        //wxPushMsg.append("-------------------------------\n\n");

        wxPushMsg.append("\uD83D\uDD25<a href=\"weixin://bizmsgmenu?msgmenucontent=获取爆文&msgmenuid=+++\">换一批爆文</a>\t");
        wxPushMsg.append("\uD83D\uDD25<a href=\"weixin://bizmsgmenu?msgmenucontent=意向客户&msgmenuid=+++\">查看客户</a>");

//        wxPushMsg.append("\n\n<a href=\"weixin://bizmsgmenu?msgmenucontent=人脉广场&msgmenuid=+++\">人脉不够，我们这里有~点击这里加粉丝 >></a>");

        return wxPushMsg.toString();
    }

    //endregion

    //region 20200526版推送策略 8:20

    @Override
    public String generateUserPushArticleInfoSecond(Integer userId,String profile) throws Exception {
        PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(profile);

        //log.info("********** ArticleServiceImpl generateUserPushArticleInfoV3"+",[userId]="+userId+",[pushTimeType]="+pushTimeType);

        UserInfo userInfo = userService.queryUserInfo(userId);

        if (userInfo == null) {
            return "";
        }

        List<UserBrandInfo> userBrandInfoList = userBrandService.getUserSubBrandInfo(userId);

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        List<ArticleInfo> brandArticleInfoList = Lists.newArrayListWithExpectedSize(10);


        //如果没有设置关注的品牌，则直播2篇，正能量2篇，情感2篇，健康1篇
        //最多8篇，不然超出 微信 内容限制
        if (CollectionUtils.isEmpty(userBrandInfoList)) {

            typeArticleInfoList = getAllToBePushTypeArticleInfo_PushKDXT(userId, 3, 0, 2, 1, profile);
        }

        //如果用户只关注了一个品牌，则该品牌取热度最高的3篇，且一周之内不能重复推送
        if (userBrandInfoList.size() == 1) {

            brandArticleInfoList = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 2);
            List<ArticleInfo> brandVideoInfoList = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(0), 2);
            brandArticleInfoList.addAll(brandArticleInfoList.size(), brandVideoInfoList);

            List<ArticleInfo> typeVideoInfoList = getAllToBePushTypeVideoInfo(userId, 1, 0, 0, 0);
            typeArticleInfoList.addAll(0, typeVideoInfoList);

            typeArticleInfoList.addAll(typeVideoInfoList.size(), getAllToBePushTypeArticleInfo_PushKDXT(userId, 1, 0, 0, 0, SpringContextUtil.getActiveProfile()));

        } else if (userBrandInfoList.size() >= 2) {

            //用户关注了两个品牌，则各取热度最高的2篇，且一周之内不能重复推送
            List<ArticleInfo> brandArticleInfoListOne = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 1);
            List<ArticleInfo> brandArticleInfoListTwo = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(1), 1);
            List<ArticleInfo> brandVideoInfoListOne = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(0), 1);
            List<ArticleInfo> brandVideoInfoListTwo = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(1), 1);

            brandArticleInfoList.addAll(brandArticleInfoListOne);
            brandArticleInfoList.addAll(brandArticleInfoListTwo);
            brandArticleInfoList.addAll(brandArticleInfoList.size(), brandVideoInfoListOne);
            brandArticleInfoList.addAll(brandArticleInfoList.size(), brandVideoInfoListTwo);

            List<ArticleInfo> typeVideoInfoList = getAllToBePushTypeVideoInfo(userId, 1, 0, 0, 0);
            typeArticleInfoList.addAll(0, typeVideoInfoList);


            typeArticleInfoList.addAll(typeVideoInfoList.size(), getAllToBePushTypeArticleInfo_PushKDXT(userId, 1, 0, 0, 0, SpringContextUtil.getActiveProfile()));
        }

        final String frontDomain = sysGzh.getSysGzh().getRealmMessage();

        StringBuffer wxPushMsg = new StringBuffer();

        String gzhTitle = "";
        if (profile != null && profile.equals("prodzx1")) {//装小编
            gzhTitle = "装修";
        } else if (profile != null && profile.equals("prodhyxt")) { //护眼学堂
            gzhTitle = "护眼";
        } else if (profile != null && profile.equals("prodshjj")) { //私护之家
            gzhTitle = "私护";
        } else if (profile != null && profile.equals("prodbkwz")) { //鼻康微站
            gzhTitle = "鼻康";
        } else if (profile != null && profile.equals("back_zkt")) { //测试
            gzhTitle = "鼻康";
        }

        if(SysConstant.CLICK_BACK_GZH_ARR.contains(profile)) {
            wxPushMsg.append("✅ 领取文章 \uD83C\uDF00 点击蓝色文章标题，拉到底部领取⬇⬇\n\n");
        }else {
            wxPushMsg.append("☀早上好，今日" + gzhTitle + "好文已送达，请查收：\n\n");
        }

        String isActivity = sysRealmMessageMapper.getConfigValueByKey(SysConstant.IsActivity);
        if (userInfo.getVipStatus() == null || userInfo.getVipStatus().equals(0)) { //非会员
            String vipMsgKey = SysConstant.VIP_8;
            if (isActivity.equals("1") && !notInvolvedInActivities.contains("|" + profile + "|")) { //活动状态下，而且 不包含在 “不参与活动的公众号名单”中
                vipMsgKey = SysConstant.VIP_P_8_A;
            }

            String strVip = messageDictInfoService.getLinkMsgByKey(vipMsgKey, frontDomain, profile) + "\n\n";
            wxPushMsg.append(strVip);
        }

        //封装生成文章的方法 start  hyl 20210113
        if(SysConstant.CLICK_BACK_GZH_ARR.contains(profile)) {
            wxPushMsg.append(getArticleInfoUrlClick(brandArticleInfoList, typeArticleInfoList, profile, userId));
        }else {
            wxPushMsg.append(getArticleInfoUrl(brandArticleInfoList, typeArticleInfoList, profile, userId, frontDomain));
        }
        //封装生成文章的方法 end

        //wxPushMsg.append("-------------------------------\n\n");

        wxPushMsg.append("\uD83D\uDD25<a href=\"weixin://bizmsgmenu?msgmenucontent=获取爆文&msgmenuid=+++\">换一批爆文</a>\t");
        wxPushMsg.append("\uD83D\uDD25<a href=\"weixin://bizmsgmenu?msgmenucontent=获取视频&msgmenuid=+++\">看更多视频</a>");

        wxPushMsg.append("\n\n\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=早安&msgmenuid=+++\">忘了早安打卡？回复【7】领取今日早安吧！</a>\n\n");

        if (profile != null && profile.equals("prodhyxt")) { //护眼学堂
            wxPushMsg.append("\uD83C\uDF88<a data-miniprogram-appid=\"wxb0f54660c25b84ad\" data-miniprogram-path=\"/pages/home/home\" href=\"\">" + "【上新】[哇]您的发圈神器\uD83D\uDC49护眼素材库来啦！点击>>免费体验！！</a>");
        }

        if (profile != null && profile.equals("prodshjj")) { //私护之家
            wxPushMsg.append("\uD83C\uDF88<a data-miniprogram-appid=\"wxdc3df6682cf2d1f0\" data-miniprogram-path=\"/pages/home/home\" href=\"\">" + "【上新】[哇]您的发圈神器\uD83D\uDC49私护素材库来啦！点击》》免费体验！！</a>");
        }

        if (profile != null && profile.equals("prodbkwz")) { //鼻康
            wxPushMsg.append("\uD83C\uDF88<a data-miniprogram-appid=\"wxd4c8d3462a815c5a\" data-miniprogram-path=\"/pages/home/home\" href=\"\">" + "【上新】[哇]您的发圈神器\uD83D\uDC49鼻康素材库来啦！点击》》免费体验！！</a>");
        }

        return wxPushMsg.toString();
    }

    //endregion

    //region 20200526版推送策略 11:20

    @Override
    public String generateUserPushArticleInfoFifth(Integer userId,String profile) throws Exception {
        PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(profile);

        UserInfo userInfo = userService.queryUserInfo(userId);

        if (userInfo == null) {
            return "";
        }

        List<UserBrandInfo> userBrandInfoList = userBrandService.getUserSubBrandInfo(userId);

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        List<ArticleInfo> brandArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        List<ArticleInfo> brandVideoInfoList = Lists.newArrayListWithExpectedSize(10);

        List<ArticleInfo> typeVideoInfoList = Lists.newArrayListWithExpectedSize(10);

        //如果没有设置关注的品牌，则直播2篇，正能量2篇，情感2篇，健康1篇
        //最多8篇，不然超出 微信 内容限制
        if (CollectionUtils.isEmpty(userBrandInfoList)) {

            typeArticleInfoList = getAllToBePushTypeArticleInfo_PushKDXT(userId, 4, 0, 2, 1, SpringContextUtil.getActiveProfile());
        }

        //如果用户只关注了一个品牌，则该品牌取热度最高的3篇，且一周之内不能重复推送
        if (userBrandInfoList.size() == 1) {

            brandArticleInfoList = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 2);
            brandVideoInfoList = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(0), 2);
            brandArticleInfoList.addAll(brandArticleInfoList.size(), brandVideoInfoList);

            typeArticleInfoList = getAllToBePushTypeArticleInfo_PushKDXT(userId, 1, 0, 1, 0, SpringContextUtil.getActiveProfile());


        } else if (userBrandInfoList.size() >= 2) {

            //用户关注了两个品牌，则各取热度最高的2篇，且一周之内不能重复推送
            List<ArticleInfo> brandArticleInfoListOne = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 1);
            List<ArticleInfo> brandArticleInfoListTwo = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(1), 1);
            brandArticleInfoList.addAll(brandArticleInfoListOne);
            brandArticleInfoList.addAll(brandArticleInfoListTwo);

            List<ArticleInfo> brandVideoInfoListOne = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(0), 1);
            List<ArticleInfo> brandVideoInfoListTwo = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(1), 1);
            brandArticleInfoList.addAll(brandArticleInfoList.size(),brandVideoInfoListOne);
            brandArticleInfoList.addAll(brandArticleInfoList.size(),brandVideoInfoListTwo);

            typeArticleInfoList = getAllToBePushTypeArticleInfo_PushKDXT(userId, 1, 0, 1, 0, SpringContextUtil.getActiveProfile());

        }

        final String frontDomain = sysGzh.getSysGzh().getRealmMessage();

        StringBuffer wxPushMsg = new StringBuffer();

        String nickName = "热文更新";
        if (userInfo != null && StringUtils.isNotBlank(userInfo.getNickName())) {
            nickName = userInfo.getNickName();
        }

        String isActivity = sysRealmMessageMapper.getConfigValueByKey(SysConstant.IsActivity);

        if(SysConstant.CLICK_BACK_GZH_ARR.contains(profile)) {
            wxPushMsg.append("✅ 领取文章 \uD83C\uDF00 点击蓝色文章标题，拉到底部领取⬇⬇\n\n");
        }else {
            String goodAfternoonMsg = "\uD83C\uDF5C " + nickName + "，中午好！提醒您素材已更新：\uD83D\uDCAA\n\n";
            wxPushMsg.append(goodAfternoonMsg);
        }

        if (userInfo.getVipStatus() == null || userInfo.getVipStatus().equals(0)) { //非会员

//            String vipMsgKey = SysConstant.VIP_11;
//            if (isActivity.equals("1") && !notInvolvedInActivities.contains("|" + profile + "|")) { //活动状态下，而且 不包含在 “不参与活动的公众号名单”中
//                vipMsgKey = SysConstant.VIP_P_11_A;
//            }
//
//            String strVip = messageDictInfoService.getLinkMsgByKey(vipMsgKey, frontDomain, profile) + "\n\n";
//            wxPushMsg.append(strVip);
            wxPushMsg.append(messageDictInfoService.getLinkMsgByKey(SysConstant.VIP_P_11_A2, frontDomain, profile) + "\n\n");
        }

        //封装生成文章的方法 start  hyl 20210113
        if(SysConstant.CLICK_BACK_GZH_ARR.contains(profile)) {
            wxPushMsg.append(getArticleInfoUrlClick(brandArticleInfoList, typeArticleInfoList, profile, userId));
        }else {
            wxPushMsg.append(getArticleInfoUrl(brandArticleInfoList, typeArticleInfoList, profile, userId, frontDomain));
        }
        //封装生成文章的方法 end

        wxPushMsg.append("\uD83D\uDD25<a href=\"weixin://bizmsgmenu?msgmenucontent=获取爆文&msgmenuid=+++\">换一批爆文</a>\t");
        wxPushMsg.append("\uD83D\uDD25<a href=\"weixin://bizmsgmenu?msgmenucontent=获取视频&msgmenuid=+++\">获取视频</a>\n\n");

        String funMsgKey = SysConstant.FUN_11;
        Integer number = new Random().nextInt(10) + 1;
        if (isActivity.equals("1") && !notInvolvedInActivities.contains("|" + profile + "|")) { //活动状态下，而且 不包含在 “不参与活动的公众号名单”中
            funMsgKey = SysConstant.FUN_P_11_A;
        }

        if (!funMsgKey.equals("")) {
            wxPushMsg.append(messageDictInfoService.getLinkMsgByKey(funMsgKey, frontDomain, profile).replace(SysConstant.numberStr,number.toString()) );
//            wxPushMsg.append("\n\n<a href=\"weixin://bizmsgmenu?msgmenucontent=人脉广场&msgmenuid=+++\">回复【2】领取联系方式！</a>");
        }

        return wxPushMsg.toString();
    }

    //endregion

    //region 20201111版推送策略 回复开单学堂 文章

    @Override
    public String generateUserPushArticleInfo_KDXT(Integer userId,String profile) {
        PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(profile);

        //log.info("********** ArticleServiceImpl generateUserPushArticleInfoV3"+",[userId]="+userId+",[pushTimeType]="+pushTimeType);

        UserInfo userInfo = userService.queryUserInfo(userId);

        if (userInfo == null) {
            return "";
        }

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        typeArticleInfoList = getAllToBePushTypeArticleInfo_PushKDXT(userId, 0, 4, 0, 0, SpringContextUtil.getActiveProfile());
        List<ArticleInfo> typeVideoInfoList = getAllToBePushTypeVideoInfo_KDXT(userId, 0, 1, 0, 0);
        typeArticleInfoList.addAll(typeVideoInfoList);

        final String frontDomain =sysGzh.getSysGzh().getRealmMessage();

        StringBuffer wxPushMsg = new StringBuffer();
/*
        String nickName = "热文更新";
        if (userInfo != null && StringUtils.isNotBlank(userInfo.getNickName())) {
            nickName = userInfo.getNickName();
        }
*/
        int typeArticleInfoSize = typeArticleInfoList != null ? typeArticleInfoList.size() : 0;

        wxPushMsg.append("\n");
        if (!CollectionUtils.isEmpty(typeArticleInfoList) && typeArticleInfoList.size() > 0) {

            typeArticleInfoList.forEach(info -> {
                //20200516 控制标题长度 hyl
                String articleTitle = info.getArticleTitle().length() > 30 ? info.getArticleTitle().substring(0, 29) + "…" : info.getArticleTitle();

                if (info.getResourceType() != null && info.getResourceType().equals(2)) {//2视频
                    wxPushMsg.append("\uD83C\uDFAC[短视频]<a href='" + frontDomain + "pages/video/index.html?t=2&userId=" + userId + "&articleId=" + info.getId() + "'>" + articleTitle + "</a>\n\n");
                } else {
                    wxPushMsg.append("➜ <a href='" + frontDomain + "pages/article/detail.html?t=2&userId=" + userId + "&articleId=" + info.getId() + "'>" + articleTitle + "</a>\n\n");
                }
            });
        }

        wxPushMsg.append("-------------------------------\n\n");

        wxPushMsg.append("\uD83D\uDD25<a href=\"weixin://bizmsgmenu?msgmenucontent=开单学堂&msgmenuid=+++\">更多开单技巧</a>\t");

        return wxPushMsg.toString();
    }

    //endregion

    //region 20210513版推送策略 20210513

    @Override
    public String generateUserPushArticleInfoThird(Integer userId,String profile) {

        UserInfo userInfo = userService.queryUserInfo(userId);

        if (userInfo == null) {
            return "";
        }

        StringBuffer wxPushMsg = new StringBuffer();

        String nickName = "热文更新";
        if (userInfo != null && StringUtils.isNotBlank(userInfo.getNickName())) {
            nickName = userInfo.getNickName();
        }
        wxPushMsg.append("@" + nickName + "，学会运用这些拓客功能，才能更好获得意向客户哦~\n\n");//平时

        wxPushMsg.append("\uD83C\uDF40<a href=\"weixin://bizmsgmenu?msgmenucontent=客户&msgmenuid=+++\">点击>>【查看客户】</a>\n分享了文章，想知道有谁看过，看了多久，都能帮您分析\n\n" +
                /*"⭕<a href=\"weixin://bizmsgmenu?msgmenucontent=人脉广场&msgmenuid=+++\">点击>>【人脉广场】</a>\n自己的微信粉丝不够？300万的微信人脉广场，尽请添加！\n\n" +*/
                "\uD83D\uDC6B<a href=\"weixin://bizmsgmenu?msgmenucontent=团队&msgmenuid=+++\">点击>>【团队管理】</a>\n创建自己的团队，同步分享素材，共同进步！\n\n" +
                "\uD83D\uDCB0<a href=\"weixin://bizmsgmenu?msgmenucontent=邀请有奖&msgmenuid=+++\">推荐>>【邀请奖励】</a>\n轻松推广赚钱，一份事业多份收入，大家都加入了！\n\n"+
                "\uD83D\uDD14<a href=\"weixin://bizmsgmenu?msgmenucontent=客服&msgmenuid=+++\">以上功能不太会使用？添加客服为您答疑！</a>");

        return wxPushMsg.toString();
    }

    //endregions

    //region 20200526版推送策略 21:30

    @Override
    public String generateUserPushArticleInfoForth(Integer userId,String profile) throws Exception {
        PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(profile);

        //log.info("********** ArticleServiceImpl generateUserPushArticleInfoV3"+",[userId]="+userId+",[pushTimeType]="+pushTimeType);

        UserInfo userInfo = userService.queryUserInfo(userId);

        if (userInfo == null) {
            return "";
        }

        List<UserBrandInfo> userBrandInfoList = userBrandService.getUserSubBrandInfo(userId);

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        List<ArticleInfo> brandArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        List<ArticleInfo> brandVideoInfoList = Lists.newArrayListWithExpectedSize(10);

        //如果没有设置关注的品牌，则直播2篇，正能量2篇，情感2篇，健康1篇
        //最多8篇，不然超出 微信 内容限制
        if (CollectionUtils.isEmpty(userBrandInfoList)) {
            typeArticleInfoList = getAllToBePushTypeArticleInfo_PushKDXT(userId, 3, 0, 2, 1, SpringContextUtil.getActiveProfile());
        }

        //如果用户只关注了一个品牌，则该品牌取热度最高的3篇，且一周之内不能重复推送
        //如果用户只关注了一个品牌，则该品牌取热度最高的3篇，且一周之内不能重复推送
        if (userBrandInfoList.size() == 1) {

            brandArticleInfoList = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 2);
            brandVideoInfoList = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(0), 2);
            brandArticleInfoList.addAll(brandArticleInfoList.size(), brandVideoInfoList);
            typeArticleInfoList = getAllToBePushTypeArticleInfo_PushKDXT(userId, 1, 0, 1, 0, SpringContextUtil.getActiveProfile());

        } else if (userBrandInfoList.size() >= 2) {

            //用户关注了两个品牌，则各取热度最高的2篇，且一周之内不能重复推送
            List<ArticleInfo> brandArticleInfoListOne = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 1);
            List<ArticleInfo> brandArticleInfoListTwo = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(1), 1);
            brandArticleInfoList.addAll(brandArticleInfoListOne);
            brandArticleInfoList.addAll(brandArticleInfoListTwo);

            List<ArticleInfo> brandVideoInfoListOne = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(0), 1);
            List<ArticleInfo> brandVideoInfoListTwo = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(1), 1);
            brandArticleInfoList.addAll(brandArticleInfoList.size(),brandVideoInfoListOne);
            brandArticleInfoList.addAll(brandArticleInfoList.size(),brandVideoInfoListTwo);

            typeArticleInfoList = getAllToBePushTypeArticleInfo_PushKDXT(userId, 1, 0, 1, 0, SpringContextUtil.getActiveProfile());

        }

        final String frontDomain =sysGzh.getSysGzh().getRealmMessage();

        StringBuffer wxPushMsg = new StringBuffer();

        String nickName = "热文更新";
        if (userInfo != null && StringUtils.isNotBlank(userInfo.getNickName())) {
            nickName = userInfo.getNickName();
        }

        if(SysConstant.CLICK_BACK_GZH_ARR.contains(profile)) {
            wxPushMsg.append("✅ 领取文章 \uD83C\uDF00 点击蓝色文章标题，拉到底部领取⬇⬇\n\n");
        }else {
            wxPushMsg.append(nickName + "，晚上好！今天与您分享的晚安问候是：\n\n");
        }

        String clockTimeStr = DateUtil.getFormatDate("yyyy-MM-dd", DateUtil.getCurDate());
        int clockStatus = Optional.ofNullable(userPunchClockInfoMapper.queryUserSpecialDayPunchClockStatus(userId, clockTimeStr)).orElse(0);

        //获取打卡文章信息
        PunchClockArticleInfo punchClockArticleInfo = getUserClockArticleInfo(userId);
        if (punchClockArticleInfo != null && punchClockArticleInfo.getId() != null) {

            int clockDays = userPunchClockInfoService.getUserClockDays(userId);

            if (clockStatus == 0) { //20200229 hyl，用户当天没打 才加1
                clockDays = clockDays + 1;
            }

            String punchClockArticleTitle = punchClockArticleInfo.getClockArticleTitle();

            wxPushMsg.append("\uD83C\uDF19<a href='" + frontDomain + "index.html'>晚安打卡 第 " + clockDays + " 天: " + punchClockArticleTitle + "</a>\n\n");


            //wxPushMsg.append("(\uD83D\uDC47点击下方领取晚安心语)\n\n");
        }

        String isActivity = sysRealmMessageMapper.getConfigValueByKey(SysConstant.IsActivity);
        if (userInfo.getVipStatus() == null || userInfo.getVipStatus().equals(0)) { //非会员

            String vip2MsgKey=SysConstant.VIP_21_2;
            if(isActivity.equals("1") && !notInvolvedInActivities.contains("|" + profile + "|")) { //活动状态下，而且 不包含在 “不参与活动的公众号名单”中
                vip2MsgKey=SysConstant.VIP_P_21_2_A;
            }

            String strVip = messageDictInfoService.getLinkMsgByKey(vip2MsgKey, frontDomain,profile) + "\n\n";
            wxPushMsg.append(strVip);
        }

        //封装生成文章的方法 start  hyl 20210113
        if(SysConstant.CLICK_BACK_GZH_ARR.contains(profile)) {
            wxPushMsg.append(getArticleInfoUrlClick(brandArticleInfoList, typeArticleInfoList, profile, userId));
        }else {
            wxPushMsg.append(getArticleInfoUrl(brandArticleInfoList, typeArticleInfoList, profile, userId, frontDomain));
        }
        //封装生成文章的方法 end

        wxPushMsg.append("\uD83D\uDD25<a href=\"weixin://bizmsgmenu?msgmenucontent=意向客户&msgmenuid=+++\">盘点一下今日意向客户吧~</a>\n\n");

        wxPushMsg.append("\uD83D\uDC40<a href=\"weixin://bizmsgmenu?msgmenucontent=订阅明天文章&msgmenuid=+++\">温馨提醒！回复【5】点击》订阅明日推送</a>");

        //订阅明天文章
        return wxPushMsg.toString();
    }

    //endregion

    //endregion

    //region 20200526版推送策略 换一批爆文

    @Override
    public String generateUserPushArticleInfoNext(Integer userId,String profile) throws Exception {
        PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(profile);

        UserInfo userInfo = userService.queryUserInfo(userId);

        if (userInfo == null) {
            return "";
        }

        List<UserBrandInfo> userBrandInfoList = userBrandService.getUserSubBrandInfo(userId);

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        List<ArticleInfo> brandArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        //如果没有设置关注的品牌，则直播2篇，正能量2篇，情感2篇，健康1篇
        //最多8篇，不然超出 微信 内容限制
        if (CollectionUtils.isEmpty(userBrandInfoList)) {

            typeArticleInfoList = getAllToBePushTypeArticleInfo_PushKDXT(userId, 4, 0, 2, 1, SpringContextUtil.getActiveProfile());
        }

        //如果用户只关注了一个品牌，则该品牌取热度最高的3篇，且一周之内不能重复推送
        if (userBrandInfoList.size() == 1) {

            brandArticleInfoList = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 3);
            List<ArticleInfo> brandVideoInfoList = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(0), 1);
            brandArticleInfoList.addAll(brandArticleInfoList.size(), brandVideoInfoList);

            List<ArticleInfo> typeVideoInfoList = getAllToBePushTypeVideoInfo(userId, 1, 0, 0, 0);
            typeArticleInfoList.addAll(0, typeVideoInfoList);


            typeArticleInfoList.addAll(typeVideoInfoList.size(), getAllToBePushTypeArticleInfo_PushKDXT(userId, 1, 0, 1, 0, SpringContextUtil.getActiveProfile()));


        } else if (userBrandInfoList.size() == 2) {

            //用户关注了两个品牌，则各取热度最高的2篇，且一周之内不能重复推送
            List<ArticleInfo> brandArticleInfoListOne = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 2);
            List<ArticleInfo> brandArticleInfoListTwo = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(1), 1);
            List<ArticleInfo> brandVideoInfoList = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(0), 1);

            brandArticleInfoList.addAll(brandArticleInfoListOne);
            brandArticleInfoList.addAll(brandArticleInfoListTwo);
            brandArticleInfoList.addAll(brandArticleInfoList.size(), brandVideoInfoList);

            List<ArticleInfo> typeVideoInfoList = getAllToBePushTypeVideoInfo(userId, 1, 0, 0, 0);
            typeArticleInfoList.addAll(0, typeVideoInfoList);


            typeArticleInfoList.addAll(typeVideoInfoList.size(), getAllToBePushTypeArticleInfo_PushKDXT(userId, 1, 0, 1, 0, SpringContextUtil.getActiveProfile()));


        } else if (userBrandInfoList.size() >= 3) {

            //用户关注了3个品牌
            List<ArticleInfo> brandArticleInfoListOne = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(0), 1);

            List<ArticleInfo> brandArticleInfoListTwo = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(1), 1);

            List<ArticleInfo> brandArticleInfoListThree = getToBePushBrandArticleInfo2(userId, userBrandInfoList.get(2), 1);

            List<ArticleInfo> brandVideoInfoList = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(0), 1);

            brandArticleInfoList.addAll(brandArticleInfoListOne);
            brandArticleInfoList.addAll(brandArticleInfoListTwo);
            brandArticleInfoList.addAll(brandArticleInfoListThree);
            brandArticleInfoList.addAll(brandArticleInfoList.size(), brandVideoInfoList);

            List<ArticleInfo> typeVideoInfoList = getAllToBePushTypeVideoInfo(userId, 1, 0, 0, 0);
            typeArticleInfoList.addAll(0, typeVideoInfoList);


            typeArticleInfoList.addAll(typeVideoInfoList.size(), getAllToBePushTypeArticleInfo_PushKDXT(userId, 1, 0, 1, 0, SpringContextUtil.getActiveProfile()));

        }

        //String articleAccessDomain = SysConstant.ARTICLE_ACCESS_DETAIL_DOMAIN_PROD;

        //String profile = SpringContextUtil.getActiveProfile();
//        if (SysConstant.PROFILES_ACTIVE_DEV.equals(profile)) {
//
//            articleAccessDomain = SysConstant.ARTICLE_ACCESS_DETAIL_DOMAIN_DEV;
//
//        }

        final String frontDomain =sysGzh.getSysGzh().getRealmMessage();

        StringBuffer wxPushMsg = new StringBuffer();

        String nickName = "热文更新";
        if (userInfo != null && StringUtils.isNotBlank(userInfo.getNickName())) {
            nickName = userInfo.getNickName();
        }

        //wxPushMsg.append(nickName+"\n\n");

        //封装生成文章的方法 start  hyl 20210113
        if(SysConstant.CLICK_BACK_GZH_ARR.contains(profile)) {
            wxPushMsg.append(getArticleInfoUrlClick(brandArticleInfoList, typeArticleInfoList, profile, userId));
        }else {
            wxPushMsg.append(getArticleInfoUrl(brandArticleInfoList, typeArticleInfoList, profile, userId, frontDomain));
        }
        //封装生成文章的方法 end

        wxPushMsg.append("-------------------------------\n\n");

        wxPushMsg.append("\uD83D\uDCB0<a href=\"weixin://bizmsgmenu?msgmenucontent=邀请有奖&msgmenuid=+++\">推荐会员最高奖励80元</a>\n\n");

        wxPushMsg.append("\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=获取爆文&msgmenuid=+++\">换一批爆文</a>\t" +
                "\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=更多视频&msgmenuid=+++\">更多视频</a>");

        return wxPushMsg.toString();
    }

    //endregion

    //region 20210511推送策略 换一批视频

    @Override
    public String generateUserPushVideoNext(Integer userId,String profile) throws Exception {
        PlatformSysInfo sysGzh = sysGzhService.getPlatformSysInfo(profile);

        UserInfo userInfo = userService.queryUserInfo(userId);

        if (userInfo == null) {
            return "";
        }

        List<UserBrandInfo> userBrandInfoList = userBrandService.getUserSubBrandInfo(userId);

        List<ArticleInfo> typeArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        List<ArticleInfo> brandArticleInfoList = Lists.newArrayListWithExpectedSize(10);

        //如果没有设置关注的品牌，则直播2篇，正能量2篇，情感2篇，健康1篇
        //最多8篇，不然超出 微信 内容限制
        if (CollectionUtils.isEmpty(userBrandInfoList)) {

            typeArticleInfoList = getAllToBePushTypeVideoInfo(userId, 4, 0, 0, 2);
        }

        //如果用户只关注了一个品牌，则该品牌取热度最高的3篇，且一周之内不能重复推送
        if (userBrandInfoList.size() == 1) {

            List<ArticleInfo> brandVideoInfoList = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(0), 4);
            brandArticleInfoList.addAll( brandVideoInfoList);

            List<ArticleInfo> typeVideoInfoList = getAllToBePushTypeVideoInfo(userId, 2, 0, 0, 0);
            typeArticleInfoList.addAll(0, typeVideoInfoList);

        } else if (userBrandInfoList.size() == 2) {

            //用户关注了两个品牌，则各取热度最高的2篇，且一周之内不能重复推送
            List<ArticleInfo> brandVideoInfoListOne = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(0), 2);
            List<ArticleInfo> brandVideoInfoListTwo = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(1), 2);

            brandArticleInfoList.addAll(brandVideoInfoListOne);
            brandArticleInfoList.addAll(brandVideoInfoListTwo);

            List<ArticleInfo> typeVideoInfoList = getAllToBePushTypeVideoInfo(userId, 2, 0, 0, 0);
            typeArticleInfoList.addAll( typeVideoInfoList);

        } else if (userBrandInfoList.size() >= 3) {

            //用户关注了3个品牌
            List<ArticleInfo> brandVideoInfoListOne = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(0), 2);

            List<ArticleInfo> brandVideoInfoListTwo = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(1), 1);

            List<ArticleInfo> brandVideoInfoListThree = getToBePushBrandVideoInfo(userId, userBrandInfoList.get(2), 1);

            brandArticleInfoList.addAll(brandVideoInfoListOne);
            brandArticleInfoList.addAll(brandVideoInfoListTwo);
            brandArticleInfoList.addAll(brandVideoInfoListThree);

            List<ArticleInfo> typeVideoInfoList = getAllToBePushTypeVideoInfo(userId, 2, 0, 0, 0);
            typeArticleInfoList.addAll(0, typeVideoInfoList);
        }

        final String frontDomain =sysGzh.getSysGzh().getRealmMessage();

        StringBuffer wxPushMsg = new StringBuffer();

        String nickName = "热文更新";
        if (userInfo != null && StringUtils.isNotBlank(userInfo.getNickName())) {
            nickName = userInfo.getNickName();
        }

        //wxPushMsg.append(nickName+"\n\n");

        //封装生成文章的方法 start  hyl 20210113
        if(SysConstant.CLICK_BACK_GZH_ARR.contains(profile)) {
            wxPushMsg.append(getArticleInfoUrlClick(brandArticleInfoList, typeArticleInfoList, profile, userId));
        }else {
            wxPushMsg.append(getArticleInfoUrl(brandArticleInfoList, typeArticleInfoList, profile, userId, frontDomain));
        }
        //封装生成文章的方法 end

        wxPushMsg.append("-------------------------------\n\n");

        wxPushMsg.append("\uD83D\uDCB0<a href=\"weixin://bizmsgmenu?msgmenucontent=邀请有奖&msgmenuid=+++\">推荐会员最高奖励80元</a>\n\n");

        wxPushMsg.append("\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=获取爆文&msgmenuid=+++\">换一批爆文</a>\t" +
                "\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=获取视频&msgmenuid=+++\">换一批视频</a>");

        return wxPushMsg.toString();
    }

    //endregion


    public String getArticleInfoUrl(List<ArticleInfo> brandArticleInfoList, List<ArticleInfo> typeArticleInfoList, String profile, Integer userId, String finalArticleAccessDomain) {

        StringBuffer wxPushMsg = new StringBuffer();
        List<SysRealmMessage> srm = sysRealmMessageMapper.getRealmByGzhCode(profile);
        if (!CollectionUtils.isEmpty(brandArticleInfoList) && brandArticleInfoList.size() > 0) {

            int srmNum = 0;

            for (ArticleInfo info : brandArticleInfoList) {

                if (!profile.equals("prodqkb") && !profile.equals("prodzzsq")  && !profile.equals("prodqkbpro")&& !profile.equals("prodhkbw")
                        && srm != null && srm.size() > 0) {
                    if (srmNum >= srm.size()) {
                        srmNum = 0;
                    }
                    finalArticleAccessDomain = srm.get(srmNum).getRealm();
                }

                String articleTitle = info.getArticleTitle().length() > 30 ? info.getArticleTitle().substring(0, 29) + "…" : info.getArticleTitle();

                if (info.getResourceType() != null && info.getResourceType().equals(2)) {//2视频
                    wxPushMsg.append("\uD83C\uDFAC[短视频]<a href='" + finalArticleAccessDomain + "pages/video/index.html?t=2&userId=" + userId + "&articleId=" + info.getId() + "'>" + articleTitle + "</a>\n\n");
                } else {
                    String brandName = articleInfoMapper.getArticleBrandName(info.getArticleBrandId());
                    if (brandName != null) {
                        brandName = "[" + brandName + "]";
                    }
                    wxPushMsg.append("➜ " + brandName + "<a href='" + finalArticleAccessDomain + "pages/article/detail.html?t=2&userId=" + userId + "&articleId=" + info.getId() + "'>" + articleTitle + "</a>\n\n");
                }

                srmNum++;

            }

        }

        if (!CollectionUtils.isEmpty(typeArticleInfoList) && typeArticleInfoList.size() > 0) {

            int srmNum = 0;

            for (ArticleInfo info : typeArticleInfoList) {
                if (!profile.equals("prodqkb") && !profile.equals("prodzzsq")  && !profile.equals("prodqkbpro")&& !profile.equals("prodhkbw")
                        && srm != null && srm.size() > 0) {
                    if (srmNum >= srm.size()) {
                        srmNum = 0;
                    }
                    finalArticleAccessDomain = srm.get(srmNum).getRealm();
                }

                String articleTitle = info.getArticleTitle().length() > 30 ? info.getArticleTitle().substring(0, 29) + "…" : info.getArticleTitle();

                if (info.getResourceType() != null && info.getResourceType().equals(2)) {//2视频
                    wxPushMsg.append("\uD83C\uDFAC[短视频]<a href='" + finalArticleAccessDomain + "pages/video/index.html?t=2&userId=" + userId + "&articleId=" + info.getId() + "'>" + articleTitle + "</a>\n\n");
                } else {
                    wxPushMsg.append("➜ <a href='" + finalArticleAccessDomain + "pages/article/detail.html?t=2&userId=" + userId + "&articleId=" + info.getId() + "'>" + articleTitle + "</a>\n\n");
                }

                srmNum++;

            }
        }

        return wxPushMsg.toString();
    }

    public String getArticleInfoUrlClick(List<ArticleInfo> brandArticleInfoList, List<ArticleInfo> typeArticleInfoList, String profile, Integer userId) throws Exception {

        StringBuffer wxPushMsg = new StringBuffer();
        if (!CollectionUtils.isEmpty(brandArticleInfoList) && brandArticleInfoList.size() > 0) {

            int srmNum = 0;

            for (ArticleInfo info : brandArticleInfoList) {

                Integer enStrId = SecUtil.encrypt2(info.getId());

                String articleTitle = info.getArticleTitle().length() > 30 ? info.getArticleTitle().substring(0, 29) + "…" : info.getArticleTitle();

                if (info.getResourceType() != null && info.getResourceType().equals(2)) {//2视频
                    wxPushMsg.append("\uD83C\uDFAC[短视频]<a href=\"weixin://bizmsgmenu?msgmenucontent=@视频:" + enStrId + "&msgmenuid=+++\">" + articleTitle + "</a>\n\n");
                } else {
                    String brandName = articleInfoMapper.getArticleBrandName(info.getArticleBrandId());
                    if (brandName != null) {
                        brandName = "[" + brandName + "]";
                    }
                    wxPushMsg.append("➜ " + brandName + "<a href=\"weixin://bizmsgmenu?msgmenucontent=@文章:" + enStrId + "&msgmenuid=+++\">" + articleTitle + "</a>\n\n");
                }

                srmNum++;

            }

        }

        if (!CollectionUtils.isEmpty(typeArticleInfoList) && typeArticleInfoList.size() > 0) {

            int srmNum = 0;

            for (ArticleInfo info : typeArticleInfoList) {
                Integer enStrId = SecUtil.encrypt2(info.getId());

                String articleTitle = info.getArticleTitle().length() > 30 ? info.getArticleTitle().substring(0, 29) + "…" : info.getArticleTitle();

                if (info.getResourceType() != null && info.getResourceType().equals(2)) {//2视频
                    wxPushMsg.append("\uD83C\uDFAC[短视频]<a href=\"weixin://bizmsgmenu?msgmenucontent=@视频:" + enStrId + "&msgmenuid=+++\">" + articleTitle + "</a>\n\n");
                } else {
                    wxPushMsg.append("➜ <a href=\"weixin://bizmsgmenu?msgmenucontent=@文章:" + enStrId + "&msgmenuid=+++\">" + articleTitle + "</a>\n\n");
                }

                srmNum++;

            }
        }

        return wxPushMsg.toString();
    }

    void buildKdxyClassMap() {

        KdxyClass k0 = new KdxyClass("2021-04-02", "【教你成交】绝密报告揭示“60分钟到账”的闪赚秘诀，5天狂销830万！[右箭头]点击学习0402", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&id=2249&sectionid=0&uid=1758&do=lesson&m=fy_lessonv2");
        KdxyClass k1 = new KdxyClass("2021-04-03", "【教你成交】绝密报告揭示“60分钟到账”的闪赚秘诀，5天狂销830万！[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&id=2249&sectionid=0&uid=1758&do=lesson&m=fy_lessonv2");
        KdxyClass k2 = new KdxyClass("2021-04-04", "【绝密成交术】快速写出牛X的微商吸金文案，小白一听就懂！[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&id=1835&sectionid=0&uid=1758&do=lesson&m=fy_lessonv2&wxref=mp.weixin.qq.com");
        KdxyClass k3 = new KdxyClass("2021-04-05", "【获客学院】快速赚10w秘籍，如何1小时内学会《快速收钱文案》[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&id=1804&sectionid=0&uid=1758&do=lesson&m=fy_lessonv2");
        KdxyClass k4 = new KdxyClass("2021-04-06", "【赚钱术】日赚300元，低成本副业实操课，每天10分钟，月入过万！[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&id=2049&sectionid=0&uid=1758&do=lesson&m=fy_lessonv2");
        KdxyClass k5 = new KdxyClass("2021-04-07", "【赚钱术】知识付费规模300亿，教你自己开网课，打造爆款课程年入过百万[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&id=2086&sectionid=0&uid=1758&do=lesson&m=fy_lessonv2");
        KdxyClass k6 = new KdxyClass("2021-04-08", "【获客学院】5位大咖150分钟分享课，带你私域精细化运营！成交翻3倍！[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&id=2283&sectionid=0&uid=1758&do=lesson&m=fy_lessonv2");
        KdxyClass k7 = new KdxyClass("2021-04-09", "【引流术】学会了百度精准引流，让你一年赚100万！[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&id=2064&sectionid=0&uid=1758&do=lesson&m=fy_lessonv2");
        KdxyClass k8 = new KdxyClass("2021-04-10", "【获客学院】微商新人从0开始做微商学引流，学会避坑，挣钱更速度[65节课][右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&id=1816&sectionid=0&uid=1758&do=lesson&m=fy_lessonv2");
        KdxyClass k9 = new KdxyClass("2021-04-11", "【赚钱术】视频号不知如何入手？教你深度运营视频号，从0粉丝到百万变现！[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&id=2246&sectionid=0&uid=1758&do=lesson&m=fy_lessonv2");
        KdxyClass k10 = new KdxyClass("2021-04-12", "2021最新直播技术：教你养号+无人直播引流+变现，实现获客引流→点击获取秘籍", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=2231&uid=1760");
        KdxyClass k11 = new KdxyClass("2021-04-13", "百万营销导师教你：实体门店如何通过微信群收钱78万，开始实体店赚钱之道>>点击领取导师心得", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=2243&uid=1760");
        KdxyClass k12 = new KdxyClass("2021-04-14", "卖货有困难？很难抓住客户心理？不知道该怎么跟客户沟通？此时你需要这个成功率80%的话术>>点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=1843&uid=1760");
        KdxyClass k13 = new KdxyClass("2021-04-15", "抖音矩阵800W+经验，毫无保留→从小白到赚钱大神，让你赚取直播第一桶金>>戳戳", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=2209&uid=1760");
        KdxyClass k14 = new KdxyClass("2021-04-16", "项目大咖养成计划：个人IP品牌打造训练营，助你成功带领团队冲刺百万业绩>>点击获取计划", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=2062&uid=1760");
        KdxyClass k15 = new KdxyClass("2021-04-17", "引流渠道不够多导致项目难以推广？不用慌！狼叔百度贴吧霸屏引流实战课，玩转流量→点击领取", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=2260&uid=1760");
        KdxyClass k16 = new KdxyClass("2021-04-18", "抓不准直播套路？老铖带你揭秘直播界最大的套路，直播为什么能年赚500万，疯狂大卖?→揭秘套路", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=2241&uid=1760");
        KdxyClass k17 = new KdxyClass("2021-04-19", "经常觉得自己不会销售话术，但是又想与客户推广！《0基础学好销售话术》让你把话说到用户心里>>快速查看", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=1846&uid=1760");
        KdxyClass k18 = new KdxyClass("2021-04-20", "如何快速疯狂涨精准粉丝？三招,让你有身份！有地位！说话有分量>>快速浏览", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=2220&uid=1760");
        KdxyClass k19 = new KdxyClass("2021-04-21", "为什么90%的企业和个人都没做好直播？就是因为没看这个攻略→0基础快速入门直播电商课程>>快速订阅学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=2221&uid=1760");
        KdxyClass k20 = new KdxyClass("2021-04-22", "30秒教会你朋友圈掘金秘籍！业绩翻倍！人脉变💰脉！[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=1857&uid=1759");
        KdxyClass k21 = new KdxyClass("2021-04-23", "朋友圈不刷屏成交术，这样挣💰的方式也太太太爽了吧！[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=1855&uid=1761");
        KdxyClass k22 = new KdxyClass("2021-04-24", "👉微商加粉秘籍来了‼吸粉转化实力MAX‼日精准引流2000➕‼[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=1832&uid=1759");
        KdxyClass k23 = new KdxyClass("2021-04-25", "【获客学院】一个人裂变一个团队的核心秘诀💱大咖用了都说好！[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=1828&uid=1759");
        KdxyClass k24 = new KdxyClass("2021-04-26", "引爆流量🔥疯狂下单😘让你视频号还没“爆”就先赚它一个亿❗[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=2285&uid=1759");
        KdxyClass k25 = new KdxyClass("2021-04-27", "【成交术】一节课实现你的讲台梦想！团队老大都在用的讲师高手特训营！[右箭头]点击参与", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=1848&uid=1759");
        KdxyClass k26 = new KdxyClass("2021-04-28", "【成交术】0投入0风险0人脉：朋友圈4大财源滚滚黄金打法，让你20天赚6W➕[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=2168&uid=1759");
        KdxyClass k27 = new KdxyClass("2021-04-29", "【引流课程】短视频精准引流爆破💣带你狂揽千亿客源流量💥[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=1864&uid=1759");
        KdxyClass k28 = new KdxyClass("2021-04-30", "【引流课程】小红书爆款霸屏推广秘籍💢实操一天精准引流50➕[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=2275&uid=1759");
        KdxyClass k29 = new KdxyClass("2021-05-01", "【首次公开】头条日引1000+精准流量，3分钟一篇爆文，傻瓜式操作的秘密！[右箭头]点击学习", "http://wk.meituan4.cn/app/index.php?i=2&c=entry&do=lesson&m=fy_lessonv2&id=2079&uid=1759");


        kdxyClassMap.clear();
        kdxyClassMap.put("2021-04-02", k0);
        kdxyClassMap.put("2021-04-03", k1);
        kdxyClassMap.put("2021-04-04", k2);
        kdxyClassMap.put("2021-04-05", k3);
        kdxyClassMap.put("2021-04-06", k4);
        kdxyClassMap.put("2021-04-07", k5);
        kdxyClassMap.put("2021-04-08", k6);
        kdxyClassMap.put("2021-04-09", k7);
        kdxyClassMap.put("2021-04-10", k8);
        kdxyClassMap.put("2021-04-11", k9);

        kdxyClassMap.put("2021-04-12", k10);
        kdxyClassMap.put("2021-04-13", k11);
        kdxyClassMap.put("2021-04-14", k12);
        kdxyClassMap.put("2021-04-15", k13);
        kdxyClassMap.put("2021-04-16", k14);
        kdxyClassMap.put("2021-04-17", k15);
        kdxyClassMap.put("2021-04-18", k16);
        kdxyClassMap.put("2021-04-19", k17);
        kdxyClassMap.put("2021-04-20", k18);
        kdxyClassMap.put("2021-04-21", k19);

        kdxyClassMap.put("2021-04-22", k20);
        kdxyClassMap.put("2021-04-23", k21);
        kdxyClassMap.put("2021-04-24", k22);
        kdxyClassMap.put("2021-04-25", k23);
        kdxyClassMap.put("2021-04-26", k24);
        kdxyClassMap.put("2021-04-27", k25);
        kdxyClassMap.put("2021-04-28", k26);
        kdxyClassMap.put("2021-04-29", k27);
        kdxyClassMap.put("2021-04-30", k28);
        kdxyClassMap.put("2021-05-01", k29);
    }

    class KdxyClass{
        public KdxyClass(){};

        public KdxyClass(String dateStr,String title,String link){
            this.dateStr=dateStr;
            this.title=title;
            this.link=link;
        };

        private String dateStr;
        private String title;
        private String link;

        public String getDateStr() {
            return dateStr;
        }

        public void setDateStr(String dateStr) {
            this.dateStr = dateStr;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getLink() {
            return link;
        }

        public void setLink(String link) {
            this.link = link;
        }
    }
}
